gpt4 book ai didi

java - HSM AES key 提取

转载 作者:太空宇宙 更新时间:2023-11-04 11:20:26 29 4
gpt4 key购买 nike

我有一个 Thales nShield HSM,其中创建了一个(CKA_SENSATIVE,假)AES key ,我想提取该 key ,但是我根本不知道如何在 java 中执行此操作。我的 key 创建如下所示:

CK_ATTRIBUTE[] aesKeyObject = new CK_ATTRIBUTE[14];

try
{
aesKeyObject[0] = new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY);
aesKeyObject[1] = new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_AES);
aesKeyObject[2] = new CK_ATTRIBUTE(CKA_VALUE_LEN, 32);
aesKeyObject[3] = new CK_ATTRIBUTE(CKA_TOKEN, true);
aesKeyObject[4] = new CK_ATTRIBUTE(CKA_LABEL, "TestAES".getBytes());
aesKeyObject[5] = new CK_ATTRIBUTE(CKA_PRIVATE, true);
aesKeyObject[6] = new CK_ATTRIBUTE(CKA_EXTRACTABLE, true);
aesKeyObject[7] = new CK_ATTRIBUTE(CKA_WRAP, true);
aesKeyObject[8] = new CK_ATTRIBUTE(CKA_UNWRAP, true);
aesKeyObject[9] = new CK_ATTRIBUTE(CKA_ENCRYPT, true);
aesKeyObject[10] = new CK_ATTRIBUTE(CKA_DECRYPT, true);
aesKeyObject[11] = new CK_ATTRIBUTE(CKA_TRUSTED, true);
aesKeyObject[12] = new CK_ATTRIBUTE(CKA_ID, 1550);
aesKeyObject[13] = new CK_ATTRIBUTE(CKA_SENSITIVE, false);

CK_MECHANISM mech = new CK_MECHANISM(CKM_AES_KEY_GEN);

long newAESKeyHandle = p11.C_GenerateKey(hSession, mech, aesKeyObject);
}catch(Exception e)
{
}

最佳答案

您需要使用C_GetAttributeValue函数读取生成的 key 对象的CKA_VALUE属性。

关于java - HSM AES key 提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44979671/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com