Trying to Encrypt with AES CBC I get error 112

10/23/2013 6:59:17 AM
Gravatar
Total Posts 1

Trying to Encrypt with AES CBC I get error 112

 

 

///

Here is the code for Key Generation

 

                  CryptokiCollection template = new CryptokiCollection();
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_SECRET_KEY));
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true));
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_AES));
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE, true));
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_ENCRYPT, true));
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_DECRYPT, true));
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_VALUE_LEN, 32)); // 256 - AES
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, "Just A Label"));
                template.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "8888"));
              

                key = session.GenerateKey(Mechanism.AES_KEY_GEN, template);
                

 

Here is the code for Encryption

 

 

                byte[] text = Encoding.ASCII.GetBytes(txtPlainText.Text);
                iv = new byte[16]; // IV should be 16 bytes with AES 256
                session.EncryptInit(new Mechanism(Mechanism.CKM_AES_CBC_PAD, iv), key);
                //Array.Resize(ref text, 16);
                byte[] CipherText = session.Encrypt(text);

 

Anh Help

10/29/2013 10:05:16 AM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Trying to Encrypt with AES CBC I get error 112

Error 112 means CKR_MECHANISM_INVALID  i.e. the mechanism  CKM_AES_CBC_PAD is not available on your token.

The error list is availble here: http://wiki.ncryptoki.com/How-NCryptoki-manages-PKCS-11-errors.ashx

Refer the yout token's documentation to see the supported mechanisms.