I'm learning encryption and using openssl_encrypt in PHP. I have encryption and decryption working with 2 functions, respectively. I simply pass the data to be encrypted/decrypted, and a unique ID that belongs to the user. The function returns the encrypted/decrypted data.
When the function is called, I get a PHP warning saying "openssl_encrypt(): Using an empty Initialization Vector (iv) is potentially insecure and not recommended".
I've read a little about IV's and am trying to understand if an IV is necessary in this case if I am using a unique key for each encrypted data set:
My encrypt function is setup like this:
function EncryptData($inputString,$uniqueID)
{
global $encryptKey; // Pulls out encryption key stored in a separate file
$method = 'aes256'; //Encryption Method
return openssl_encrypt($inputString,$method,$encryptKey.$uniqueID);
}
The decrypt function is nearly identical, except it decrypts instead and returns the data.
Notice that I combine the global encryption key with the user's unique ID to generate a combined key. This ensures that the key for every user is unique. Hence, this should also ensure that the encrypted data is also unique for separate users, even if the unencrypted values are identical, correct? If so, then is an IV necessary in this case? Is there an advantage to still using an IV or a disadvantage to not using an IV here?