Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate AES key with seed value

How do I Generate AES key with seed value so that whenever I generate key with same seed value,I shud be able to get the same AES key?

I want to generate this key for my Blackberry Pearl 8100 device.

I am not able to generate AES key with AESKey(keyData) .

Also whenever I print it either in the form of String or byte[] , I am not able to generate it.(print it) Actual key is never printed.

What can be done to get the key?

Update

I tried generating AESKey by passing byte[] of my data,as follws:

 AESKey key = new AESKey(keyData);

Everytime I get same key, which is correct.

Now using this key I am encrypting the data.Everytime I encrypt I get different value of encryption. Here is my problem. How can I get same data everytime after encryption,so that I can send it to server?

Update

I am not able to generate AES key with AESKey(keyData) .

Also whenever I print it either in the form of String or byte[] , I am not able to generate it.(print it) Actual key is never printed.

What can be done to get the key?

like image 968
iOSDev Avatar asked Jan 24 '23 14:01

iOSDev


2 Answers

Section 5.2 in RFC 2898 describes one way of doing this.

Specifically, the "seed" value consists of a "PASSPHRASE" and a "SALT"; but given the same passphrase and salt, will always result in the same key.

http://anandam.name/pbkdf2/ is a javascript implementation.

http://en.wikipedia.org/wiki/PBKDF2 has more information, and links to other implementations.

like image 160
Stobor Avatar answered Jan 29 '23 22:01

Stobor


This can not be done in a secure manner. You should not be generating encryption keys like this, particularly if you intend to protect anything important with the resulting keys. Nonetheless, a basic algorithm to do it looks like this (many enhancements are possible, but none will make it really secure):

  1. Choose a random number generator; probably Java has one built in that people usually use.
  2. Initialize (seed) the random number generator with a specific input value (passphrase? hash of passphrase? something like that).
  3. Take the first N bytes of RNG output; those are your encryption key. As long as you seed with the same value in step 2, the first N bytes generated will always be the same.
  4. Reseed the RNG with a different value, preferably a random one (in Python you would seed with None, for instance; that tells the machine to choose any random seed).
like image 25
kquinn Avatar answered Jan 29 '23 22:01

kquinn