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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -