pkcs#11 - 如何通过 SUNPKCS 提供商从 hsm 获取 al 别名?
问题描述
我想从 hsm 获取我的所有关键别名,但我收到此错误消息:
Exception in thread "main" java.io.IOException: load failed
at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:778)
at java.security.KeyStore.load(KeyStore.java:1445)
at eracom.provider.ProCrypt.main(ProCrypt.java:99)
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception:
CKR_OBJECT_HANDLE_INVALID
at sun.security.pkcs11.wrapper.PKCS11.C_GetAttributeValue(Native Method)
at sun.security.pkcs11.P11KeyStore.mapLabels(P11KeyStore.java:2415)
at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:770)
如果我在 hsm 上只创建一个密钥。没有问题,我可以从 hsm 获取别名,但如果我有 2 个或更多,我会收到错误消息。如何解决?
KeyStore keyStore = KeyStore.getInstance("PKCS11", pkcs11);
keyStore.load(null, slotPIN);
SecretKey key = (SecretKey) keyStore.getKey("KEY2", slotPIN);
System.out.println("key's attributes: " + key.toString());
java.util.Enumeration<String> aliases = keyStore.aliases();
String alias = null;
while (aliases.hasMoreElements()) {
alias = aliases.nextElement();
System.out.println("key label name : " + alias);
}
解决方案
推荐阅读
- swift - 如果我们单击 AddCommentsButton,则必须启用 AddCommentsTextView。如何在 swift iOS 中实现?
- android - 如何使用颤振制作安卓棋盘游戏
- azure - 是否可以在 Azure DevOps 上升级到性能更高的 Microsoft 托管构建代理?
- python - 我需要使用 json 将嵌套的 python 字典写入文本文件,该文本文件将被读取为 c++ 字典(使用 OpenFOAM)
- jquery - Owl-carousel 和 Bootstrap 模态
- android - 如何为相同的绑定编写不同的 BindingAdapter
- azure - Azure 自动化:运行手册:获取所有 AAD 组属性,例如备注/信息字段?
- ios - 如何在 Xcode 中设置语言优先级
- google-cloud-platform - 我可以将服务帐户的授权限制为 GCP 容器注册表中的特定图像吗?
- xamarin - Mono 运行时如何嵌入到 Android 应用程序中