java - PKCS11异常 : CKR_KEY_FUNCTION_NOT_PERMITTED

标签 java cryptography

你看,我有一个小程序可以根据在 pkcs11 token 中找到的 RSA 私钥解密一些信息。
在巴西,现在有一些包含 2048 位私钥的新证书。也有常规 1024 位的旧型号。
到目前为止,我的应用程序运行良好。我使用的是 1024 位证书,所以不用担心。但是现在我有一些新证书要测试,它崩溃并显示标题错误:

PKCS11Exception: CKR_KEY_FUNCTION_NOT_PERMITTED

顺便说一句:它仍然适用于 1024 位。

在 sun.applet.AppletPanel.run(未知来源) 在 java.lang.Thread.run(未知来源) 引起:sun.security.pkcs11.wrapper.PKCS11Exception:CKR_KEY_FUNCTION_NOT_PERMITTED 在 sun.security.pkcs11.wrapper.PKCS11.C_DecryptInit( native 方法) 在 sun.security.pkcs11.P11RSACipher.initialize(P11RSACipher.java:260) 在 sun.security.pkcs11.P11RSACipher.implInit(P11RSACipher.java:193)

我使用标准的 java 安全命名空间。我在某处读到 Java 在政策上有限制,与美国如何对待安全有关,我不知道......
有关系吗?
我知道我必须使用 bouncyCaSTLe 提供程序,但我只是想知道...

重要的是,BC 不能使用 P11PrivateKey,因为它使用硬件进行签名或加密。

结论:

正如我所发现的,感谢 owlstead,在 etoken 属性中, key 不是为那只海豚制作的......天啊......

不起作用的那个:

Serial number: (...)
Issued to: (...)
Issued by: (...)
Valid from: (...)
Valid until: (...)
Intended purposes: Client Authentication,Secure Email
Key size: 2048 bits
Container name: (...)
Modulus: (...)
Key specification: AT_KEYSIGNATURE

另一个,有效的:

Serial number: (...)
Issued to: (...)
Issued by: (...)
Valid from: (...)
Valid until: (...)
Intended purposes: Secure Email,Client Authentication,Smart Card Logon
Key size: 1024 bits
Container name: (...)
Modulus: (...)
Key specification: AT_KEYEXCHANGE
Default Key Container: Yes
Auxiliary Key Container: Yes

我知道AT_KEYEXCHANGE 本身并不意味着可以解密,但是拥有AT_KEYSIGNATURE 意味着只能用于该海豚。正如我测试过的那样,它适用于签名......

最佳答案

与Java key 长度无关。尽管如此,Java 可能甚至不知道 key 大小,因为 key 保留在硬件 token 上。更有可能的是属性 CKA_ENCRYPT 被设置为 CK_FALSE 的 CK_BBOOL 值。

来自 PKCS#11 v2.20 (cryptoki)

CKR_KEY_FUNCTION_NOT_PERMITTED: An attempt has been made to use a key for a cryptographic purpose that the key’s attributes are not set to allow it to do. For example, to use a key for performing encryption, that key must have its CKA_ENCRYPT attribute set to CK_TRUE (the fact that the key must have a CKA_ENCRYPT attribute implies that the key cannot be a private key). This return value has lower priority than CKR_KEY_TYPE_INCONSISTENT.

关于java - PKCS11异常 : CKR_KEY_FUNCTION_NOT_PERMITTED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8887218/

相关文章:

java - 如何从 AES-256 切换到 AES-128?

objective-c - NSString 的 AES 加密?

java - flutter 中是否有任何类可以像处理程序一样工作?

java - 是否可以在嵌套循环中添加条件 for 循环?

java - Java 中的 BufferedReader 和 InputStreamReader

php - 加密:使用初始化向量与 key ?

java - 服务器意外停止读取客户端消息

java - 什么是 "allocation pools for temporary objects"?

c - 计算商而不跟踪余数的除法算法

javascript - 对于具有样式表处理指令的文档,XAdES 验证失败,引用 URI 为 =""