Source Code : Java Key Tools
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Java Key Tools
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
public class KeyTools {
public static void writeToFile(Key key, File file) throws IOException {
FileOutputStream fileoutputstream = new FileOutputStream(file);
ObjectOutputStream objectoutputstream = new ObjectOutputStream(fileoutputstream);
objectoutputstream.writeObject(key);
objectoutputstream.close();
}
public static void main(String[] rgstring) {
try {
File filePublic = new File(rgstring[0]);
File filePrivate = new File(rgstring[1]);
KeyPairGenerator keypairgenerator = KeyPairGenerator.getInstance("DSA");
keypairgenerator.initialize(1024, new SecureRandom());
KeyPair keypair = keypairgenerator.generateKeyPair();
writeToFile(keypair.getPublic(), filePublic);
writeToFile(keypair.getPrivate(), filePrivate);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Thank with us