3 回答

TA貢獻1858條經驗 獲得超8個贊
答案是:您不能直接將私鑰導入 SafeNet Luna HSM。您必須首先加密(包裝)私鑰,然后才能將其傳輸到 HSM。有關如何執行此操作的答案,請參閱PKCS#11 unwrap private key to HSM 。

TA貢獻1789條經驗 獲得超10個贊
不幸的是,PKCS#11 API 沒有提供來自提供的模板的確切屬性導致錯誤的詳細信息,但是許多 PKCS#11 庫支持某種內部日志記錄機制,這可能會揭示錯誤的真正原因。啟用日志記錄所需的確切步驟應包含在 PKCS#11 庫供應商提供的文檔中。
我的猜測是你收到CKR_TEMPLATE_INCONSISTENT是因為你設置CKA_SENSITIVE為true. 以明文形式導入的私鑰已經失去了“敏感性”,因為它暴露在外部環境中。我在 Pkcs11Interop.X509Store 項目中成功使用了以下模板:
var privateKeyAttributes = new List<ObjectAttribute>()
{
new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_PRIVATE_KEY),
new ObjectAttribute(CKA.CKA_TOKEN, true),
new ObjectAttribute(CKA.CKA_PRIVATE, true),
new ObjectAttribute(CKA.CKA_MODIFIABLE, true),
new ObjectAttribute(CKA.CKA_LABEL, ...),
new ObjectAttribute(CKA.CKA_ID, ...),
new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_RSA),
new ObjectAttribute(CKA.CKA_MODULUS, rsaPrivKeyParams.Modulus.ToByteArrayUnsigned()),
new ObjectAttribute(CKA.CKA_PUBLIC_EXPONENT, rsaPrivKeyParams.PublicExponent.ToByteArrayUnsigned()),
new ObjectAttribute(CKA.CKA_PRIVATE_EXPONENT, rsaPrivKeyParams.Exponent.ToByteArrayUnsigned()),
new ObjectAttribute(CKA.CKA_PRIME_1, rsaPrivKeyParams.P.ToByteArrayUnsigned()),
new ObjectAttribute(CKA.CKA_PRIME_2, rsaPrivKeyParams.Q.ToByteArrayUnsigned()),
new ObjectAttribute(CKA.CKA_EXPONENT_1, rsaPrivKeyParams.DP.ToByteArrayUnsigned()),
new ObjectAttribute(CKA.CKA_EXPONENT_2, rsaPrivKeyParams.DQ.ToByteArrayUnsigned()),
new ObjectAttribute(CKA.CKA_COEFFICIENT, rsaPrivKeyParams.QInv.ToByteArrayUnsigned())
};
- 3 回答
- 0 關注
- 460 瀏覽
添加回答
舉報