You are here

private function McryptAES128Encryption::decryptLegacyDataWithMcrypt in Two-factor Authentication (TFA) 8

Decrypt using the deprecated Mcrypt extension.

@noinspection PhpDeprecationInspection

Parameters

string $text: The text to be decrypted.

string $key: The key to decrypt the text with.

Return value

string The decrypted text

1 call to McryptAES128Encryption::decryptLegacyDataWithMcrypt()
McryptAES128Encryption::decrypt in src/Plugin/EncryptionMethod/McryptAES128Encryption.php
Decrypt text.

File

src/Plugin/EncryptionMethod/McryptAES128Encryption.php, line 125

Class

McryptAES128Encryption
Deprecated Mcrypt AES 128 encryption plugin.

Namespace

Drupal\tfa\Plugin\EncryptionMethod

Code

private function decryptLegacyDataWithMcrypt($text, $key) {

  // Key cannot be too long for this encryption.
  $key = mb_substr($key, 0, 32);

  // Define iv cipher.
  $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
  $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  $text = base64_decode($text);

  // Decrypt text.
  return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_ECB, $iv));
}