Saving Private Key / Public Key to a File and Retreiving
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, June 24, 2002 08:19 AM

Thats the code I've written to Save and then read the same public key from a file. But when I try to use the keyFactory to instantiate it, it throws an OutOfMemory exception. Can somebody please tell me what I'm doing wrong? I'm using the DSA method. protected String saveOpenReadPublicKey(PublicKey pubKey) { /** Testing the writing of Public Key to file **/ try { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("pubkey.pub")); byte[] tempPubKey = pubKey.getEncoded(); System.out.println("Length = " + tempPubKey.length); out.write(tempPubKey); out.close(); DataInputStrea   More>>

Thats the code I've written to Save and then read the same public key from a file. But when I try to use the keyFactory to instantiate it, it throws an OutOfMemory exception. Can somebody please tell me what I'm doing wrong?



I'm using the DSA method.


			
protected String saveOpenReadPublicKey(PublicKey pubKey)
{
/** Testing the writing of Public Key to file
**/
try
{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("pubkey.pub"));
byte[] tempPubKey = pubKey.getEncoded();
System.out.println("Length = " + tempPubKey.length);
out.write(tempPubKey);
out.close();

DataInputStream in = new DataInputStream(new FileInputStream("pubkey.pub"));
byte[] pubKeyEncoded = new byte[tempPubKey.length];
in.read(pubKeyEncoded);
in.close();

X509EncodedKeySpec encodedPubKeySpec = new X509EncodedKeySpec(pubKeyEncoded);
KeyFactory kF = KeyFactory.getInstance("DSA");
Key newPubKey = kF.generatePublic(encodedPubKeySpec);
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
return "nothing";
}




Thanks

   <<Less
About | Sitemap | Contact