A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Store PrivateKey PublicKey in DB
Joined: Mar 15, 2005
Nov 07, 2007 13:05:00
I am trying to store
objects in a MySQL database. From an example in another post here at the forum:
The code example from that posts are:
Use the getEncoded() method to get the byte from the keys. To go the other way, getting an
from a byte, use the appropriate
methods and encoded key specs, e.g. for
// byte  encodedKey contains the RSA private key retrieved from the DB KeyFactory rsaKeyFac = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(encodedKey); RSAPrivateKey privKey = (RSAPrivateKey)rsaKeyFac.generatePrivate(encodedKeySpec);
KeyFactory rsaKeyFac = KeyFactory.getInstance("RSA"); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encKey); RSAPublicKey pubKey = (RSAPublicKey )rsaKeyFac .generatePublic(keySpec);
I succeed in storing and retreiving the private key as in the first example. But when I try the public key conversion from byte array to a
object I get the following exception:
Exception in thread "main" java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: algid parse error, not a sequence at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:163) at java.security.KeyFactory.generatePublic(KeyFactory.java:304)
Somebody have a clue why the
example does not work?
Joined: Aug 10, 2006
Nov 10, 2007 07:06:00
I cannot be sure without looking at the file in question. I would have to guess that the encoded public key is not in the correct format or has simply been retrieved incorrectly.
Nice to meet you.
I agree. Here's the link:
subject: Store PrivateKey PublicKey in DB
public key retrieval from DB incorrect
Reading a .der (file generated by openssl rsageberate command) file from classpath
Encryption & Decryption Problem with "JDK default" provider
invalidkeyspecexception - PKCS8EncodedKeySpec
How to store PublicKey and PrivateKey in database??
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014