You are here

public static function LockrAes128CtrSha256KeyWrapper::reencrypt in Lockr 7.2

Same name and namespace in other branches
  1. 7.3 vendor/lockr/lockr/src/KeyWrapper/LockrAes128CtrSha256KeyWrapper.php \Lockr\KeyWrapper\LockrAes128CtrSha256KeyWrapper::reencrypt()

Encrypt the given plaintext using the same initial state as defined by encoded.

Parameters

string $plaintext:

string $encoded:

Return value

array

Overrides KeyWrapperInterface::reencrypt

File

vendor/lockr/lockr-client/src/KeyWrapper/LockrAes128CtrSha256KeyWrapper.php, line 88

Class

LockrAes128CtrSha256KeyWrapper

Namespace

Lockr\KeyWrapper

Code

public static function reencrypt($plaintext, $encoded) {
  $parts = self::decode($encoded);
  if (!$parts) {
    return false;
  }
  list($key, $iv, $hmac_key) = $parts;
  $ciphertext = openssl_encrypt($plaintext, self::METHOD, $key, OPENSSL_RAW_DATA, $iv);
  $hmac = self::hmac($ciphertext, $hmac_key);
  return array(
    'ciphertext' => base64_encode($hmac) . base64_encode($ciphertext),
    'encoded' => $encoded,
  );
}