You are here

function lockr_migrate_encrypt in Lockr 7.3

Same name and namespace in other branches
  1. 7.2 lockr.forms.inc \lockr_migrate_encrypt()
1 call to lockr_migrate_encrypt()
lockr_migrate_keys_form in ./lockr.forms.inc

File

./lockr.forms.inc, line 101

Code

function lockr_migrate_encrypt($plaintext, $enc_key, $hmac_key) {
  $iv = random_bytes(16);
  $ciphertext = openssl_encrypt($plaintext, 'aes-256-cbc', $enc_key, OPENSSL_RAW_DATA, $iv);
  $hmac_data = 'aes-256-cbc' . $iv . $ciphertext;
  $hmac = hash_hmac('sha256', $hmac_data, $hmac_key, TRUE);
  return $iv . $ciphertext . $hmac;
}