I used a function in pgcrypto
- encrypt('id','TheBestSecretKey','aes')
to encrypt a field in postgresql(Pg admin tool)
.The field got encrypted and the output was in bytea format like:\234u\321\036\027\317O\371\020bb\342\334x)\236
. The same data when encrypted using aes (using javax.crypto library) in java gave me string output as : œuÑÏOùbbâÜx)ž
.
I have a requirement where I need to compare both these values in my java program. How can I compare these two fields.
Asked
Active
Viewed 1,547 times
0
-
1That is a weird requirement. Ciphertext should always be "salted" with a random IV, so that if you encrypt the same text twice it *does not* result in the same ciphertext. Otherwise you can do dictionary attacks. The only way to get anything useful from "proper" ciphertext is to decrypt it. – Thilo Aug 26 '16 at 09:16
-
1`Arrays.toString(data.toByteArray())` – xenteros Aug 26 '16 at 09:19
-
1Having said that, are you sure these two outputs are not the same? They have the same length, and all the readable characters `u`, `b` and `)` are in the same positions. – Thilo Aug 26 '16 at 09:19
-
@Thilo These are the encrypted value of the same data .One encrypted in postgresql the other in a java program.Both are encrypted using aes with the same key. – bhavanak Aug 26 '16 at 09:23
-
@bhavanak: Yes. And they look the same to me. Look at the byte values in Java, too (don't turn it into a String). – Thilo Aug 26 '16 at 09:24