For Programmers: Free Programming Magazines  


Home > Archive > Java Security > November 2005 > String to PrivateKye









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author String to PrivateKye
Marco Zilotti

2005-11-14, 7:02 pm

Hi all, I have a small problem with java, i need to convert a strig key
to a privatekey

I generate a RSA keypair and i write my privatekey into a file

try
{
FileWriter out = new FileWriter ("key.txt");
out.write(myprivatekey);
out.close();
}

where myprivatekey is a string
PrivateKey kpriv = kp.getPrivate();
myprivatekey = (kpriv+"");

But now, if i want to retrive the key i have an error in cast

try {
BufferedReader in = new BufferedReader(new
FileReader("key.txt"));
String str,bo="";
while ((str = in.readLine()) != null) {
bo = bo+"\n"+str;
}
in.close();

kpriv = (PrivateKey)bo; <-- error (crypto1.java:71: inconvertible
types)

Can anyone help me in this cast ? Thanks a lot

Marco Zilotti

2005-11-14, 7:02 pm

I solve with ObjectOutputStream :D

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com