Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Exception while re-creating Private key from byte array

843811Apr 12 2009 — edited Apr 12 2009
Hi,

What I am doing is -

- Generating a 2048 RSA Private key
- Encrypting it using a 192 AES Key
- Hex encoding the encrypted key bytes and saving this hex string in the database.

- I retrieve this hex string from the database
- Get the decrypted private key bytes from this string.All works fine till here.
- Now I need to get the Private key object from this decrypted key bytes.To achieve this I do the following -

PrivateKey PK = KeyFactory.getInstance("RSA","BC").generatePrivate(
new PKCS8EncodedKeySpec(decryptedKeyBytes));

The error I get is -

java.security.spec.InvalidKeySpecException: java.io.IOException: DER length more than 4 bytes

Any pointers on what is wrong here.

Regards,
Nishanth Nair
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2009
Added on Apr 12 2009
4 comments
2,045 views