You are here

protected function TfaBasePlugin::decryptLegacyDataWithMcrypt in Two-factor Authentication (TFA) 7.2

Decrypt using the deprecated Mcrypt extension.

Parameters

string $data: The data to be decrypted.

Return value

string The plaintext, or empty string on failure.

1 call to TfaBasePlugin::decryptLegacyDataWithMcrypt()
TfaBasePlugin::decrypt in ./tfa.inc
Decrypt a encrypted string.

File

./tfa.inc, line 703
TFA module classes.

Class

TfaBasePlugin
Base plugin class.

Code

protected function decryptLegacyDataWithMcrypt($data) {
  $td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
  $iv = substr($data, 0, mcrypt_enc_get_iv_size($td));
  $data = substr($data, mcrypt_enc_get_iv_size($td));
  $key = substr($this->encryptionKey, 0, mcrypt_enc_get_key_size($td));
  mcrypt_generic_init($td, $key, $iv);
  $decrypted_text = mdecrypt_generic($td, $data);

  // Return only the message and none of its padding.
  list($length, $padded_data) = explode('|', $decrypted_text, 2);
  $text = substr($padded_data, 0, $length);
  mcrypt_generic_deinit($td);
  mcrypt_module_close($td);
  return $text;
}