So I'm using mcrypt_encrypt in PHP to encrypt some data going into my database.
It's seeming that values it encrypted a while ago are now different to values it's encrypting (for checking) today.
For example...
1234 Was originally encrypted to 4321 and put into the database.
1234 Is now being encrypted again, I expect it to encrypt to 4321 so that it can match the encryption in the database. Except, 1234 is now being encrypted to 2314 so it can't find the 4321 in the database.
The function to encrypt is exactly the same and hasn't changed. The salt is the same.
Is there any reason the following might return different results at different times?
trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
I might add that no matter what it gets encrypted to, they do actually decrypt correctly to the same original value. But that doesn't help with checking the (encrypted) value in the database.