如何解决Java - 获取 KeyStore 中刚刚加载的 Entry 的别名
我正在尝试使用 .pfx
证书对 XML 进行签名,签名在只有一个证书的测试环境中工作正常,但在生产中,我的系统将存储许多 .pfx
证书。如何获取刚刚使用 load()
方法加载的证书的别名?
...
// Load the KeyStore and get the signing key and certificate.
KeyStore ks = KeyStore.getInstance("PKCS12");
// certPath contain the path for the .pfx file
ks.load(new FileInputStream(certPath),password.toCharArray()); // How to get the alias for this certificate that was just loaded
String alias = ks.aliases().nextElement(); // This works only if the keystore has one just one loaded entry
KeyStore.PrivateKeyEntry keyEntry =
(KeyStore.PrivateKeyEntry) ks.getEntry(alias,new KeyStore.PasswordProtection(password.toCharArray()));
X509Certificate cert = (X509Certificate) keyEntry.getCertificate(); // Get the just added certificate
...
如果我做错了其他事情并且存在使用 .pfx
对 XML 进行签名的更简单方法,请告诉我。
提前致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。