php - How to securely generate an IV for AES CBC Encryption? -
I work on some crypto stuff.
- I use AES 256 with CEC mode
- I use OPENSSL
I have the following things (source = Wikipedia ):
There should be an initalization vector:
- Unique: Do not be repeated for any encrypted message with a given key
- Unexpected: An attacker who sees messages of any number and their information is about to predict next one with their IV Should not be more than 50% per bit of success (i.e., indistinguishable from random)
My question is, how to prepare IV with OPENSSL and PHP safely? I know that there is such a functionality in lib mcrypt ()
I did not find anything to do with OPENSSL (creating unique and unpredictable IV)
(with most other parameters set in the current parameter, which you should check that Is set to
TRUE ). This will generate IVS with appropriate random characteristics.
$ isIceSecure = false; $ Iv = openssl_random_sepseudo_bytes (16, $ eitscher); If ($$ then it was safe) {// We're good to go! } Else {// Unprotected results failed, stop moving}
Alternatively, PHP 7 offers which is very easy.
Comments
Post a Comment