Search code examples
vb.nethsm

How to change public exponent attribute to be a byte array


I am working on Luna G5 HSM, and need to generate key pair. I have the code as follows, but there is an error said I need to change the public exponent attribute to be a byte array, but I don't know how to modify this part, any help would be really appreciate.

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"))

Solution

  • Replace the public exponent line with this one:

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