aspose file tools*
The moose likes Security and the fly likes How use the same SecretKey (not random each time it runs) ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "How use the same SecretKey (not random each time it runs) ?" Watch "How use the same SecretKey (not random each time it runs) ?" New topic
Author

How use the same SecretKey (not random each time it runs) ?

Daniel Rodriguez Hernandez
Greenhorn

Joined: Nov 26, 2009
Posts: 13
Hi everybody.

I need to encrypt and decrypt using the same SecretKey for AES, but if you use the method "GenerateKey ()", it generates a new key every time ..

Is there a way to encrypt and decrypt with a key defined by me, not creating a new one every time?

Thank you.
greg stark
Ranch Hand

Joined: Aug 10, 2006
Posts: 220
use a SecretKeySpec.


Nice to meet you.
Daniel Rodriguez Hernandez
Greenhorn

Joined: Nov 26, 2009
Posts: 13
Ok, thank you..

I used SecretKeySpec but it threw me a "Invalid length key 7 bytes"... Then I read that the key must be of length 16 bytes... i.e, a character per byte, 16 character..

Now It works fine.

Thank you
 
Don't get me started about those stupid light bulbs.
 
subject: How use the same SecretKey (not random each time it runs) ?