1 回答

TA贡献1836条经验 获得超5个赞
经过几天的搜索,我找到了解决方案。为了访问 KeySet,我直接访问 KeyStore 而不是获取密钥,而是使用 X509 证书创建公钥并使用它来加密任何文本。
char [] passch = password.toCharArray();
com.ibm.crypto.provider.JavaKeyStore keystore = new JavaKeyStore();
keystore.engineLoad(new FileInputStream(new File(pathKeyFileJKS)), null);
KeyStore.TrustedCertificateEntry privKeyEntry = (TrustedCertificateEntry)
keystore.engineGetEntry("eecc-KeyStore", new KeyStore.PasswordProtection(passch));
X509CertImpl cert = (X509CertImpl) privKeyEntry.getTrustedCertificate();
cert.checkValidity();
PublicKey publicKey = cert.getPublicKey();
其中password变量包含我用来创建 eecc_public.key 文件的密码,pathKeyFileJKS包含创建 jks 文件的路径,“eecc-KeyStore”是我用来在 WebSphere Server 中创建我的 keyStore 的名称。
添加回答
举报