Java AES Encryption with salt

cody picture cody · Sep 5, 2011 · Viewed 32.4k times · Source

Alright, turns out I suck at Encryption/Decryption. I just dont get it. How can I make Java encrypt String message1 = "hello world"; with String salt = "mySalt"; using AES encryption? also how can I decrypt it once encrypted?

If you have the time to provide the most basic code, it would help me a lot.

Also 1 general question about AES encryption, using the same salt, will the same message always have the same encryption?

Thanks in advance.

Answer

Oliver Charlesworth picture Oliver Charlesworth · Sep 5, 2011

AES doesn't have a concept of a salt. It just takes data, and a key. For the same input, it will always generate the same output.

How you combine your message with your salt is up to you. String concatenation is probably sufficient. But note that salts don't really make a lot of sense for something like AES, because it's not a hash algorithm.