views:

1914

answers:

6

Hi,

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.

Please help.

Thanks.

Hi again,

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?

Please help,badly stuck in this issue.

A: 

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).
kquinn
Is there any link or url to achieve all this.Really your answer is useful.ThanksBapi
Deepak
Thanks KQuinn for your quick reply
imMobile
It is done all the time. Its called password-based encryption. Secure key derivation algorithms are defined in PKCS #5.
erickson
+6  A: 

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.

Stobor
Thanks Stobor for the reply
imMobile
A: 

Hi, 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?

Please help me out!

Thanks.

imMobile
Does it matter if the encrypted blocks are different, if they decrypt to the same thing? AES (and many other encryption schemes) are designed to hide the fact that the original message is the same, by encrypting it differently each time. But when it is decrypted, it should come out the same.For details, see the other answer CBC and initialization vectors.If you _really_ need them to be identical, you need to use AES in ECB ([Electronic Code Book](http://en.wikipedia.org/wiki/Cipher_block_chaining#Electronic_codebook_.28ECB.29)) mode.
Stobor
A: 

Also I faced the same problem recently. Still now did not get any solution for that

Thanks, Deepak

Deepak
A: 

I need a bit more info, so this is a guess.

How are you using your AESKey? If you're doing things using CBC Encryption (i.e. with the net.rim.device.api.crypto.CBCEncryptorEngine) then your initialization vector has to be the same for each invocation too. Use the constructor for CBCEncryptorEngine that takes an InitializationVector as well as a BlockEncryptorEngine.

Wikipedia article with more info on why this is so.

Anthony Rizk
A: 

Hi again,

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?

Please help,badly stuck in this issue.

imMobile