You are here

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

Encrypt using the deprecated Mcrypt extension.

@noinspection PhpDeprecationInspection

Parameters

string $text: The text to be encrypted.

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

Return value

string The encrypted text.

1 call to McryptAES128Encryption::encryptWithMcrypt()
McryptAES128Encryption::encrypt in src/Plugin/EncryptionMethod/McryptAES128Encryption.php
Encrypt text.

File

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

Class

McryptAES128Encryption
Deprecated Mcrypt AES 128 encryption plugin.

Namespace

Drupal\tfa\Plugin\EncryptionMethod

Code

private function encryptWithMcrypt($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);
  $processed_text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_ECB, $iv);
  $processed_text = base64_encode($processed_text);
  return $processed_text;
}