Template Inconsistent error

2/12/2013 11:28:47 AM
Gravatar
Total Posts 1

Template Inconsistent error

Dear Ugo,
I'm currently using your sample project as a basis for creating an AES CBC encryption key from Thales PKCS#11 dll.  When it calls the generatekey on the session object it returns error number 209  TEMPLATE_INCONSISTENT   error.  Am I missing an attribute for the key creation?  The code is posted below.
Thanks,
Surajit Mukherjee

 

CryptokiCollection templatePub = new CryptokiCollection();
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_SECRET_KEY));
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_AES));
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, "JasonKey"));
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "1"));
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true));
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE, true));
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_ENCRYPT, true));
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_DECRYPT, true));
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_VALUE_LEN, 32));

Key keys1 = session.GenerateKey(Mechanism.AES_KEY_GEN, templatePub);



 

2/13/2013 3:15:59 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Template Inconsistent error

Hi

error TEMPLATE_INCONSISTENT comes from the underlying PKCS#11 module from Thales HSM.

Usually it means that some of the attributes in the template aren't valid.

First of all try to remove this line

templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_VALUE_LEN, 32));

Maybe Thales HSM doesn't want this attribute.