我想将3个证书和3个私钥保存到密钥库中。
KeyStore store;
PrivateKeyEntry CAprivKeyEntry = new PrivateKeyEntry(pair.getPrivate(), (X509Certificate[]) chain);
TrustedCertificateEntry CAcertEntry = new TrustedCertificateEntry(caCert);
PrivateKeyEntry interPrivKeyEntry = new PrivateKeyEntry(interPair.getPrivate(), chain);
TrustedCertificateEntry interCertEntry = new TrustedCertificateEntry(interCert);
PrivateKeyEntry subjectPrivKeyEntry = new PrivateKeyEntry(subPair.getPrivate(), chain);
TrustedCertificateEntry subjectCertEntry = new TrustedCertificateEntry(subjectCert);
try {
store = KeyStore.getInstance(storeType);
store.load(null, storePassword.toCharArray());
store.setEntry("CA", CAprivKeyEntry, new KeyStore.PasswordProtection(storePassword.toCharArray()));
store.setEntry("CA", CAcertEntry, null);
store.setEntry("Intermediate", interPrivKeyEntry, new KeyStore.PasswordProtection(storePassword.toCharArray()));
store.setEntry("Intermediate", interCertEntry, null);
store.setEntry("Subject", subjectPrivKeyEntry, new KeyStore.PasswordProtection(storePassword.toCharArray()));
store.setEntry("Subject", subjectCertEntry, null);
FileOutputStream out = new FileOutputStream(new File(storePath));
store.store(out, storePassword.toCharArray());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
它带来KeyStoreException:无法覆盖自己的证书
我该如何解决这个问题?