问题描述
我正在尝试使用 .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 (将#修改为@)