/ Published in: Java
                    
                                        
Save/Load or.. Write/Read or.. Store/Retrieve Private Key/Public Key to/from disk/file :D
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
package net.java.edem;
import java.io.*;
import java.security.*;
import java.security.spec.*;
public class Adam {
Adam adam = new Adam();
try {
String path = "C:\\Documents and Settings\\george\\My Documents\\workspaces\\gsoc09\\playground\\tmp";
keyGen.initialize(1024);
adam.dumpKeyPair(generatedKeyPair);
adam.SaveKeyPair(path, generatedKeyPair);
adam.dumpKeyPair(loadedKeyPair);
e.printStackTrace();
return;
}
}
}
for (int i = 0; i < b.length; i++) {
}
return result;
}
// Store Public Key.
publicKey.getEncoded());
fos.write(x509EncodedKeySpec.getEncoded());
fos.close();
// Store Private Key.
privateKey.getEncoded());
fos.write(pkcs8EncodedKeySpec.getEncoded());
fos.close();
}
// Read Public Key.
byte[] encodedPublicKey = new byte[(int) filePublicKey.length()];
fis.read(encodedPublicKey);
fis.close();
// Read Private Key.
byte[] encodedPrivateKey = new byte[(int) filePrivateKey.length()];
fis.read(encodedPrivateKey);
fis.close();
// Generate KeyPair.
encodedPublicKey);
encodedPrivateKey);
}
}
URL: http://java.sun.com/docs/books/tutorial/security/apisign/vstep2.html
Comments
 Subscribe to comments
                    Subscribe to comments
                
                