1

我在我的 HSM 中创建了一个 AES 密钥,我想获取密钥值,我尝试了 C_FindObjects 但它只返回密钥 hundel。

    public long Find_AES_Key(String label) {
            long hkey = -1L; 
            try {
                 AESSecretKey keyTemplate = new AESSecretKey();
                 keyTemplate.getLabel().setCharArrayValue(label.toCharArray());
                 CK_ATTRIBUTE[] attributes = iaik.pkcs.pkcs11.objects.Object.getSetAttributes(keyTemplate);
                    
                 cryptoki.C_FindObjectsInit(ckiSession, attributes, false);
                 long[] found = cryptoki.C_FindObjects(ckiSession, 1L);
                 cryptoki.C_FindObjectsFinal(ckiSession);
                 
                 hkey = found[0];
                 // cryptoki.C_GetAttributeValue(ckiSession, hkey, attributes, true);
                                 
             }catch(Exception e) {
                 e.printStackTrace();
             }
            return hkey;
         }

谢谢您的帮助。

4

1 回答 1

1

这取决于您的 HSM,但在大多数情况下,如果密钥是在 HSM 内部生成的,它们也不是“可读”的。

如果可能的话,您可以Wrap使用C_DeriveKey/C_WrapKey调用将其导出。

检查密钥的CKA_WRAP属性。

于 2021-02-25T16:51:50.610 回答