You are here

class SystemStatusEncryption in System Status 8

Hierarchy

Expanded class hierarchy of SystemStatusEncryption

2 files declare their use of SystemStatusEncryption
SystemStatusController.php in src/Controller/SystemStatusController.php
Contains \Drupal\pants\Controller\SystemStatusController.
system_status.install in ./system_status.install
Installation file for system_status.

File

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

Namespace

Drupal\system_status\Controller
View source
class SystemStatusEncryption {

  /**
   * System Status: create a new token.
   */
  public static function getToken() {
    $chars = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'), range(0, 99));
    shuffle($chars);
    $token = "";
    for ($i = 0; $i < 8; $i++) {
      $token .= $chars[$i];
    }
    return $token;
  }

  /**
   * System Status: encrypt a plaintext message.
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SystemStatusEncryption::encrypt public static function System Status: encrypt a plaintext message.
SystemStatusEncryption::getToken public static function System Status: create a new token.