是否可以KeyPair
使用已生成的公钥和私钥库 (JKS) 文件在我的应用程序中生成使用?
谢谢
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048);
KeyPair keypair = keyGen.genKeyPair();
我想用已经生成的RSA 2048
私钥和公钥创建密钥对
你可以像下面这样使用:
public static KeyPair loadKeyStore(final File keystoreFile,
final String password, final String alias, final String keyStoreType)
throws Exception {
if (null == keystoreFile) {
throw new IllegalArgumentException("Keystore url may not be null");
}
final KeyStore keystore = KeyStore.getInstance(keyStoreType);
InputStream is = null;
try {
is = new FileInputStream(keystoreFile);
keystore.load(is, null == password ? null : password.toCharArray());
} finally {
if (null != is) {
is.close();
}
}
final PrivateKey key = (PrivateKey) keystore.getKey(alias,
password.toCharArray());
final Certificate cert = keystore.getCertificate(alias);
final PublicKey publicKey = cert.getPublicKey();
return new KeyPair(publicKey, key);
}