0

The follow line allow me to generate a SecretKey

 SecretKey key = KeyGenerator.getInstance("DES").generateKey();

But I want to generate a SecretKey related to a specific String.

For example

String myKeyStr="abcde";

SecretKey mykey2=keyGeneratedFrom(myKeyStr);

Obviously the SecretKey generation should have a 1:1 link to avoid issue during the decryption.

I have no idea of how to solve this problem.

Could you help me?

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
AndreaF
  • 11,975
  • 27
  • 102
  • 168

1 Answers1

1

Passwords are not keys. You have to use something like PBKDF2 to derive a key from a password. Even then, it pays to have secure passwords. There is a lot of information about PBKDF2 when used in Java, and the Bouncy Castle library can help too.

Etcetera.

Don't forget to use a random salt.

Community
  • 1
  • 1
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263