KeyTool 클래스에 대해 알지 못합니다. 공개 API가 아니기 때문에이를 사용하는 것이 싫지만 KeyStore 클래스를 사용하여 키스트 아를 읽고 쓸 수 있습니다. 그 간단한 것, 내가 PFX (PKCS12 키 저장소)를 만드는 방법을 알고 일부러
public void convertKeystore(Path sourceKeystorePath,
char[] sourceKeystorePassword,
Path destKeystorePath,
char[] destKeystorePassword)
throws GeneralSecurityException, IOException {
KeyStore sourceKeystore = KeyStore.getInstance("jks");
try (InputStream stream =
new BufferedInputStream(
Files.newInputStream(sourceKeystorePath))) {
sourceKeystore.load(stream, sourceKeystorePassword);
}
KeyStore destKeystore = KeyStore.getInstance("pkcs12");
destKeystore.load(null, destKeystorePassword);
// Assume each alias in a keystore has the same password
// as the keystore itself.
KeyStore.ProtectionParameter sourceAliasPassword =
new KeyStore.PasswordProtection(sourceKeystorePassword);
KeyStore.ProtectionParameter destAliasPassword =
new KeyStore.PasswordProtection(destKeystorePassword);
Enumeration<String> aliasList = sourceKeystore.aliases();
while (aliasList.hasMoreElements()) {
String alias = aliasList.nextElement();
KeyStore.Entry entry =
sourceKeystore.getEntry(alias, sourceAliasPassword);
destKeystore.setEntry(alias, entry, destAliasPassword);
}
try (OutputStream stream =
new BufferedOutputStream(
Files.newOutputStream(destKeystorePath))) {
destKeystore.store(stream, destKeystorePassword);
}
}
출처
2013-03-23 13:43:34
VGR
감사하십시오 documentation에 따르면, 자바는 최소의
jks
및pkcs12
키 스토어 유형에서 지원, 그래서 당신은 뭔가를 할 수 있습니다. 나는 그것을 시험해 볼 것이다. – wolvorinePk