Forums Register Login

casting String to SecretKey object

+Pie Number of slices to send: Send
Hi,

please give help urgent....
In my servlet i am encrypting one message (say userId or pswd)
for encryption i am using javax.crypto package algoritham used is DES
I am generating key as ..
-----------code--------
SecretKey key =KeyGenerator.getInstance("DES").generateKey();
------------------
Then converting it into String and passing it as requestparameter along with encrypted message.
(this is step i can't change ie i need to pass these as requestParameter)

In the second servlet for decryption i need this key ,I am getting that but
I am not able to cast it to SecretKey object
any solution related to this will be great for me..
or any method to reproduce the same key in the second servlet as in first servlet used for encryption.
Any method is available for generating a key with respect to a String given hardcoded...
+Pie Number of slices to send: Send
The Security Guide in the JDK documentation gives an example that includes code converting a key to a byte array, and later converting the byte array back into a key. The example uses a public key, but secret keys are handled in an analogous way. All that remains to do is Base64 encoding it.

I will not ask what you hope to achieve by sending an encrypted message together with its key in an HTTP request :roll:

- Peter
[ July 28, 2004: Message edited by: Peter den Haan ]
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2605 times.
Similar Threads
Convertion between SecretKey to String or byte
JCE Code
Encryption: communicating with other systems
Encryption using javax.crypto
InvalidKeyException in 3DES
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:01:28.