I´m using this code to Encrypt and Decrypt in Java and Android some Strings and in each system I get a different value.
The code I’m using comes from http://www.androidsnippets.com/encryptdecrypt-strings (I won’t paste it beacuse it’s quite big).
For example in Android for encrypting “aa” I get this:
1C6BD31C57F42ACFD0EDD2DD5B7A92CA
and exactly the same String with the same key as seed in Java I get:
61FAD1203B7AC92AD9345771AA273DA5
Any idea?
Thanks in advance!
This is just my guess, but I think the reason is your key derivation. I’m not really a Java developer though, so I might not be understanding the code correctly.
This code always calls getRawKey() when you encrypt and decrypt. getRawKey() looks like it takes something they call a seed, or your shared secret, and uses it to compute a new random key to do the actual encryption/decryption.
According to Java docs found here, setSeed() “Reseeds this random object. The given seed supplements, rather than replaces, the existing seed.”
My guess is that the initial state of the RNG is different on each system/platform, and thus it’s giving you different results. You should fix the key derivation to something more standard and consistent, or use an already established crypto system, like PGP in the Bouncy Castle libraries.