protected function TfaBasePlugin::decrypt in Two-factor Authentication (TFA) 7.2
Decrypt a encrypted string.
Should be used when reading codes from storage.
Parameters
string $data: The encrypted text.
Return value
string The plaintext, or empty string on failure.
1 call to TfaBasePlugin::decrypt()
- TfaTestTotp::readFromStore in tests/
includes/ tfa_test.totp.inc - One-off methods that allow for testing base plugin encryption.
File
- ./
tfa.inc, line 675 - TFA module classes.
Class
- TfaBasePlugin
- Base plugin class.
Code
protected function decrypt($data) {
$crypto_data = drupal_json_decode($data);
if (empty($crypto_data['version']) || empty($crypto_data['iv_base64']) || empty($crypto_data['ciphertext_base64'])) {
// Backwards compatibility with the old Mcrypt scheme.
if (extension_loaded('mcrypt')) {
return $this
->decryptLegacyDataWithMcrypt($data);
}
if (extension_loaded('openssl')) {
return $this
->decryptLegacyDataWithOpenSSL($data);
}
return '';
}
$iv = base64_decode($crypto_data['iv_base64']);
$ciphertext = base64_decode($crypto_data['ciphertext_base64']);
return openssl_decrypt($ciphertext, 'aes-256-cbc', $this->encryptionKey, TRUE, $iv);
}