You are here

public static function SystemStatusEncryption::encrypt in System Status 6.2

Same name and namespace in other branches
  1. 7 system_status_encryption.inc \SystemStatusEncryption::encrypt()

System Status: encrypt a plaintext message.

1 call to SystemStatusEncryption::encrypt()
system_status_status_page in ./system_status_status.page.inc
Return JSON formatted module information.

File

./system_status_encryption.inc, line 31
Encryption logic for system_status

Class

SystemStatusEncryption
@file Encryption logic for system_status

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);
}