How to generate cryptographic key in the form of a binary string 16 bytes long in PHP -
i trying store string in encrypted form in mysql db, looking 2 way encryption, found guide openssl_encrypt / openssl_decrypt
$ciphertext = openssl_encrypt($plaintext, 'aes-128-cbc', $key, openssl_raw_data, $iv); $plaintext = openssl_decrypt($ciphertext, 'aes-128-cbc', $key, openssl_raw_data, $iv);
that guide doesn't explain how generate cryptographic key in form of binary string 16 bytes long $key
, crypto-secure random binary string 16 bytes long $iv
.
any appreciated.
$key = openssl_random_pseudo_bytes(16);
, $iv = openssl_random_pseudo_bytes(16);
should generate random 16 byte / 128-bit key , iv.
Comments
Post a Comment