I would like to encrypt a string ( user’s email ) and always obtain the same resulting string
I am saving the user’s email as login user name, because I have searches on that field ( for example, user’s email already exists when registering. Or select user’s password where email = ‘abc’ )
For password encryption and decryption I use Jasypt which does the job.
String encryption, I can encrypt and decrypt but I haven’t found a way to have the decryption constant.
I have searched a lot for the solution but none seem to address my problem. It is possible I am not using the right keywords, I am not familiar with encryption.
I don’t have to use Jasypt for the string encryption. anything that transforms “hello@hello.com” into “@ABC#EFG” every time would be great.
I have also tried scrambling the bytes of the string using different scrambling algorithms according to length of string, first letter etc. Unfortunately, it stops working when I save the encrypted string in MySQL. From what I understand, every byte which ends up having a Unicode value that MySQL doesn’t like is not saved correctly ( it works fine when I use a string present in the test class, but not when I actually save encrypted String and retrieve from DB )
Any ideas – links to solution?
Thanks very much in advance, Dan
Just have a look at any hash methods. MD5, SHA-1, SHA-256 can be obtained using MessageDigest. Just get the bytes of your original strings (using
getBytes("UTF-8")), and you should have always the same result.