で鍵ペアを作成したい:
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);
}
パラメータ「最終ファイルいるkeystoreFile」についてパブリックキーストアまたはプライベートキーストアを渡しますか? – user3520080
プライベートキーストアをロードすると、このコードの例外が発生します。「例外がスレッド内にあります」メイン「java.security.UnrecoverableKeyException:キーを回復できません」 – user3520080
問題は鍵とパスワードの両方が異なるためです。証明書パス。私は少しコードを更新し、それは動作します – user3520080