public function McryptAES128Encryption::decrypt in Two-factor Authentication (TFA) 8
Decrypt text.
Parameters
string $text: The text to be decrypted.
string $key: The key to decrypt the text with.
Return value
string The decrypted text
Throws
\Drupal\encrypt\Exception\EncryptException Thrown when decryption fails.
\Drupal\encrypt\Exception\EncryptionMethodCanNotDecryptException The method should throw this exception when the plugin can not decrypt (i.e. use a public key).
Overrides EncryptionMethodInterface::decrypt
File
- src/
Plugin/ EncryptionMethod/ McryptAES128Encryption.php, line 81
Class
- McryptAES128Encryption
- Deprecated Mcrypt AES 128 encryption plugin.
Namespace
Drupal\tfa\Plugin\EncryptionMethodCode
public function decrypt($text, $key) {
$crypto_data = Json::decode($text);
if (empty($crypto_data['version']) || empty($crypto_data['iv_base64']) || empty($crypto_data['ciphertext_base64'])) {
// Backwards compatibility with the old Mcrypt scheme.
return extension_loaded('mcrypt') ? $this
->decryptLegacyDataWithMcrypt($text, $key) : $this
->decryptLegacyDataWithOpenSsl($text, $key);
}
else {
$iv = base64_decode($crypto_data['iv_base64']);
$ciphertext = base64_decode($crypto_data['ciphertext_base64']);
return openssl_decrypt($ciphertext, 'aes-256-cbc', $key, TRUE, $iv);
}
}