public static function LockrAes128CtrSha256KeyWrapper::encrypt in Lockr 7.2
Same name and namespace in other branches
- 7.3 vendor/lockr/lockr/src/KeyWrapper/LockrAes128CtrSha256KeyWrapper.php \Lockr\KeyWrapper\LockrAes128CtrSha256KeyWrapper::encrypt()
Encrypt the given plaintext.
Parameters
string $plaintext:
Return value
array
Overrides KeyWrapperInterface::encrypt
File
- vendor/
lockr/ lockr-client/ src/ KeyWrapper/ LockrAes128CtrSha256KeyWrapper.php, line 25
Class
Namespace
Lockr\KeyWrapperCode
public static function encrypt($plaintext) {
$key = openssl_random_pseudo_bytes(32);
$iv_len = openssl_cipher_iv_length(self::METHOD);
$iv = openssl_random_pseudo_bytes($iv_len);
$ciphertext = openssl_encrypt($plaintext, self::METHOD, $key, OPENSSL_RAW_DATA, $iv);
$hmac_key = openssl_random_pseudo_bytes(32);
$hmac = self::hmac($ciphertext, $hmac_key);
return array(
'ciphertext' => base64_encode($hmac) . base64_encode($ciphertext),
'encoded' => self::encode($key, $iv, $hmac_key),
);
}