This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Security and the fly likes Store PrivateKey PublicKey in DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » Security
Bookmark "Store PrivateKey PublicKey in DB" Watch "Store PrivateKey PublicKey in DB" New topic

Store PrivateKey PublicKey in DB

Lasse Bergstr�m

Joined: Mar 15, 2005
Posts: 2

I am trying to store PrivateKey and PublicKey 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 RSAPublicKey or RSAPrivateKey from a byte[], use the appropriate KeyFactory methods and encoded key specs, e.g. for RSAPrivateKey

and for RSAPublicKey

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 PublicKey object I get the following exception:

Somebody have a clue why the PublicKey example does not work?

Best regards

greg stark
Ranch Hand

Joined: Aug 10, 2006
Posts: 220
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
It's not a secret anymore!