You are here

public static function LockrAes128CtrSha256KeyWrapper::encrypt in Lockr 7.3

Same name and namespace in other branches
  1. 7.2 vendor/lockr/lockr-client/src/KeyWrapper/LockrAes128CtrSha256KeyWrapper.php \Lockr\KeyWrapper\LockrAes128CtrSha256KeyWrapper::encrypt()

Encrypt the given plaintext.

Parameters

string $plaintext:

string|null $key:

Return value

array

Overrides KeyWrapperInterface::encrypt

2 calls to LockrAes128CtrSha256KeyWrapper::encrypt()
LockrAes128CtrSha256KeyWrapperTest::testEncryptsData in vendor/lockr/lockr/tests/KeyWrapper/LockrAes128CtrSha256KeyWrapperTest.php
LockrAes128CtrSha256KeyWrapperTest::testReencryptsData in vendor/lockr/lockr/tests/KeyWrapper/LockrAes128CtrSha256KeyWrapperTest.php

File

vendor/lockr/lockr/src/KeyWrapper/LockrAes128CtrSha256KeyWrapper.php, line 23

Class

LockrAes128CtrSha256KeyWrapper

Namespace

Lockr\KeyWrapper

Code

public static function encrypt($plaintext, $key = null) {
  if (is_null($key)) {
    $key = openssl_random_pseudo_bytes(16);
  }
  $iv_len = openssl_cipher_iv_length(self::METHOD);
  $iv = openssl_random_pseudo_bytes($iv_len);
  $hmac_key = openssl_random_pseudo_bytes(32);
  return self::doEncrypt($plaintext, $key, $iv, $hmac_key);
}