Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Daniel Rodriguez Hernandez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a SecretKeySpec.
 
Daniel Rodriguez Hernandez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic