You are here

protected static function LockrAes256CbcSha256KeyWrapper::doEncrypt in Lockr 7.2

Same name and namespace in other branches
  1. 7.3 vendor/lockr/lockr/src/KeyWrapper/LockrAes256CbcSha256KeyWrapper.php \Lockr\KeyWrapper\LockrAes256CbcSha256KeyWrapper::doEncrypt()
2 calls to LockrAes256CbcSha256KeyWrapper::doEncrypt()
LockrAes256CbcSha256KeyWrapper::encrypt in vendor/lockr/lockr-client/src/KeyWrapper/LockrAes256CbcSha256KeyWrapper.php
Encrypt the given plaintext.
LockrAes256CbcSha256KeyWrapper::reencrypt in vendor/lockr/lockr-client/src/KeyWrapper/LockrAes256CbcSha256KeyWrapper.php
Encrypt the given plaintext using the same initial state as defined by encoded.

File

vendor/lockr/lockr-client/src/KeyWrapper/LockrAes256CbcSha256KeyWrapper.php, line 74

Class

LockrAes256CbcSha256KeyWrapper

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' => base64_encode($iv . $ciphertext . $hmac),
    'encoded' => self::PREFIX . base64_encode($key),
  ];
}