如何将公共指数属性更改为字节数组

时间:2017-07-11 15:23:25

标签: vb.net hsm

我正在研究Luna G5 HSM,需要生成密钥对。我有如下代码,但有一个错误说我需要将public exponent属性更改为一个字节数组,但我不知道如何修改这部分,任何帮助都会非常感激。

templatePub = new CryptokiCollection()
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS,CryptokiObject.CKO_PUBLIC_KEY))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_SENSITIVE, false))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_MODIFIABLE, false))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_EXTRACTABLE, false))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_ENCRYPT, true))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_VERIFY, true))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_WRAP, true))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_DERIVE, false))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_MODULUS_BITS, 2048))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_PUBLIC_EXPONENT, 0x010001))
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "60"));
         templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, "public key"))


        templatePri = new CryptokiCollection()
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_PRIVATE_KEY))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_SENSITIVE, true))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_MODIFIABLE, false))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_EXTRACTABLE, false))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_DECRYPT, true))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_SIGN, true))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_UNWRAP, true))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_DERIVE, false))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "60"))
         templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, "private key"))

1 个答案:

答案 0 :(得分:0)

将公共指数行替换为:

templatePub.Add(New ObjectAttribute(ObjectAttribute.CKA_PUBLIC_EXPONENT, &H10001))