retreiving a private key from a file
hi guys,
i have created a RSA key pair and have used the public key for encryption and converted the private key to base 64 and stored on it the system as a txt file.
publicstatic PublicKey keyGenerator()throws Exception{
//try{
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("rsa");
keyGen.initialize(512);
KeyPair KeyPair = keyGen.generateKeyPair();
PublicKey pubk = KeyPair.getPublic();
PrivateKey prvk = KeyPair.getPrivate();
saveprvKey(prvk);
//} catch(Exception ex) {
//System.out.println("Exception: " + ex);
//ex.printStackTrace();
//}
return pubk;
}
privatestaticvoid saveprvKey(PrivateKey prvky)throws Exception{
byte[] byteSeed = prvky.getEncoded();
BASE64Encoder encoder =new BASE64Encoder();
String seed = encoder.encodeBuffer(byteSeed);
FileWriter fw =new FileWriter("f:/privkey.txt");
fw.write(seed);
fw.close();
}
publicstatic PrivateKey loadPrvkey()throws Exception{
FileInputStream fis =new FileInputStream("f:/privkey.txt");
byte[] encKey =newbyte[fis.available()];
fis.read(encKey);
fis.close();
String seed =new String(encKey);
BASE64Decoder decoder =new BASE64Decoder();
byte[] byteSeed = decoder.decodeBuffer(seed);
PrivateKey prvKey =new PrivateKey(byteSeed);
return prvKey;
}
i am now having problems getting this back.
the line that it doesnt like is
PrivateKey prvKey =new PrivateKey(byteSeed);
once the key has been retrieved it is going to be sent to the decrypt method.
any help would be great!

