You are here

protected static function LockrAes256CbcSha256RawKeyWrapper::doEncrypt in Lockr 7.3

2 calls to LockrAes256CbcSha256RawKeyWrapper::doEncrypt()
LockrAes256CbcSha256RawKeyWrapper::encrypt in vendor/lockr/lockr/src/KeyWrapper/LockrAes256CbcSha256RawKeyWrapper.php
Encrypt the given plaintext.
LockrAes256CbcSha256RawKeyWrapper::reencrypt in vendor/lockr/lockr/src/KeyWrapper/LockrAes256CbcSha256RawKeyWrapper.php
Encrypt the given plaintext reusing state.

File

vendor/lockr/lockr/src/KeyWrapper/LockrAes256CbcSha256RawKeyWrapper.php, line 76

Class

LockrAes256CbcSha256RawKeyWrapper

Namespace

Lockr\KeyWrapper

Code

protected static function doEncrypt($plaintext, $key, $iv) {
  $key_data = hash('sha512', $key, true);
  $enc_key = substr($key_data, 0, self::KEY_LEN);
  $hmac_key = substr($key_data, self::KEY_LEN);
  $ciphertext = openssl_encrypt($plaintext, self::METHOD, $enc_key, OPENSSL_RAW_DATA, $iv);
  $hmac = self::hmac($iv, $ciphertext, $hmac_key);
  return [
    'ciphertext' => $iv . $ciphertext . $hmac,
    'encoded' => self::PREFIX . base64_encode($key),
  ];
}