Exception while re-creating Private key from byte array
843811Apr 12 2009 — edited Apr 12 2009Hi,
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