You are here

protected function KeyClient::encrypt in Lockr 7

1 call to KeyClient::encrypt()
KeyClient::set in src/Lockr/KeyClient.php
Sets a key in Lockr.

File

src/Lockr/KeyClient.php, line 131

Class

KeyClient

Namespace

Lockr

Code

protected function encrypt($plaintext) {
  $cipher = MCRYPT_RIJNDAEL_256;
  $mode = MCRYPT_MODE_CBC;
  $key = openssl_random_pseudo_bytes(32);
  $iv_len = mcrypt_get_iv_size($cipher, $mode);
  $iv = mcrypt_create_iv($iv_len);
  $ciphertext = mcrypt_encrypt($cipher, $key, $plaintext, $mode, $iv);
  $ciphertext = base64_encode($ciphertext);
  $encoded = $this
    ->encode($cipher, $mode, $iv, $key);
  return array(
    $ciphertext,
    $encoded,
  );
}