keytool -genkey -alias test -keyalg RSA -keystore c:/key.store
keytool -export -alias 别名 -keystore 文件名 -file 证书名称
但是我们无法通过KEYTOOL工具来提取私钥的..我们只能通过Java的KeyStore类getEntry() 或者getKey()来提取私钥.
char[] password = "password".toCharArray();
java.io.FileInputStream fis = new java.io.FileInputStream("c:/server/server_keystore");
// 从指定的输入流中加载此 KeyStore
ks.load(fis, password);
//keystore 中的每一项都用“别名”字符串标识。
//使用指定保护参数获取指定别名的 keystore Entry
。
//KeyStore.PrivateKeyEntry 保存 PrivateKey
和相应证书链的 KeyStore
项。
方法2. PrivateKey key = (PrivateKey) ks.getKey("ser", password);
怎么来验证提取的私钥是否正确呢?(因为公钥私钥必须成对出现,我们可以通过证书提取去公钥,然后用公钥加密,使用刚刚获得的私钥解密)
keytool -export -alias 别名 -keystore 文件名 -file 证书名称
转自:http://blog.csdn.net/madun/article/details/8677783