INVINCI
INVINCI

Reputation: 15

random secret key generator using fixed seed java

I want to generate a secret key (128 bit) based upon some predefined seed value .

Currently i am using javax.crypto.KeyGenerator (AES) to generate key using secureRandom .

How can i pass my own seen rather than using secureRandom object .

code i am currently using :

//

KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128,SecureRandom random); // 128 bits key size
key = kgen.generateKey();

//

Thank You ..

Upvotes: 1

Views: 3428

Answers (1)

ug_
ug_

Reputation: 11440

You can set the seed of the SecureRandom.

SecureRandom random = new SecureRandom();
random.setSeed(1000L);

When testing this i did notice that to get consistant results you had to recreate the KeyGenerator if you changed the seed at any time.

Upvotes: 1

Related Questions