You are here

public static function SystemStatusEncryption::encrypt in System Status 8

System Status: encrypt a plaintext message.

1 call to SystemStatusEncryption::encrypt()
SystemStatusController::load in src/Controller/SystemStatusController.php
Changes Sensei's pants and returns the display of the new status.

File

src/Controller/SystemStatusEncryption.php, line 32
Encryption logic for system_status

Class

SystemStatusEncryption

Namespace

Drupal\system_status\Controller

Code

public static function encrypt($plaintext) {
  $key = hash("SHA256", variable_get('system_status_encrypt_token', 'Error-no-token'), TRUE);
  $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
  $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  $plaintext_utf8 = utf8_encode($plaintext);
  $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext_utf8, MCRYPT_MODE_CBC, $iv);
  $ciphertext = $iv . $ciphertext;
  return base64_encode($ciphertext);
}