Generate AES key with seed value

一笑奈何 提交于 2019-12-23 15:04:10

问题


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?


回答1:


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.




回答2:


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).



回答3:


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.



来源:https://stackoverflow.com/questions/861679/generate-aes-key-with-seed-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!