You are here

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

Encrypt using the deprecated Mcrypt extension.

Parameters

string $text: The text to encrypt.

Return value

string The text encrypted using Mcrypt.

1 call to TfaBasePlugin::encryptWithMcrypt()
TfaBasePlugin::encrypt in ./tfa.inc
Encrypt a plaintext string.

File

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

Class

TfaBasePlugin
Base plugin class.

Code

protected function encryptWithMcrypt($text) {
  $td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
  $iv = drupal_random_bytes(mcrypt_enc_get_iv_size($td));
  $key = substr($this->encryptionKey, 0, mcrypt_enc_get_key_size($td));
  mcrypt_generic_init($td, $key, $iv);

  // Encrypt with message length so decryption can return message without
  // padding.
  $text = strlen($text) . '|' . $text;
  $data = mcrypt_generic($td, $text);
  mcrypt_generic_deinit($td);
  mcrypt_module_close($td);
  return $iv . $data;
}