Error 113

11/19/2013 9:36:43 AM
Gravatar
Total Posts 1

Error 113

Hello,

 

I'm trying to port an encryption call that I'm able to make successfully using the PKCS11 wrapper, but is not working right using nCryptoki.

I'm getting an error 113 on the EncryptInit method. Any idea why this is happening? I checked the available mechanisms coming from the HSM and CKM_AES_CBC_PAD is listed.

 

The code looks like this...

 

stringFromCRM = "555-55-5555";
byte[] valueFromCRM = UTF8Encoding.UTF8.GetBytes(stringFromCRM);

byte[] parameter = new byte[16];
Mechanism m = new Mechanism(Mechanism.CKM_AES_CBC_PAD, parameter);


int retVal = stateObject.session.EncryptInit(m, stateObject.secretKey);
if (retVal != 0)
{
Console.Write("Error initializing ENcryption");
//throw new InvalidOperationException("Error Initializing Encryption");
return stateObject;
}
else
{
byte[] ciphertext = stateObject.session.Encrypt(valueFromCRM);
string encryptedvalue = Convert.ToBase64String(ciphertext);

ec.Entities[index]["fi_taxid"] = encryptedvalue;
Console.WriteLine("Set TaxId = " + encryptedvalue + " for ContactId " + ec.Entities[index]["fi_id"]);
stateObject.orgService.Update(ec.Entities[index]);
return stateObject;
}
 

11/25/2013 10:06:16 AM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Error 113

Hi, 

error 113 means CKR_MECHANISM_PARAM_INVALID

i.e. the param passed is invalid.

 

BTW. the list of all errors is here: http://wiki.ncryptoki.com/How-NCryptoki-manages-PKCS-11-errors.ashx

 

11/26/2013 7:05:12 AM
Gravatar
Total Posts 1

Re: Error 113

Ugo,

 

When I run what Jason is trying to do against an older version of NCryptoki (1.5.4.2), it works.  Run against the latest version (1.6.1.1), it does not.  Same exact code:

 

Mechanism m = new Mechanism((int)(Mechanism.CKM_AES_CBC_PAD), new byte[16]);

int result = session.EncryptInit(mech, secretKey); // With a previously found and loaded SecretKey.

 

This gives no error when run against the 1.5.4.2 version of NCryptoki, but results in the 0x00000071 (decimal 113) error code when run against the 1.6.1.1 version.  In that latter case, the error is returned by the underlying Cryptoki implementation (cknfast.dll for an nShield HSM).

 

Did something change between those two versions in the way you process parameters for mechanisms? 

 

Thanks,

S

ander

11/26/2013 4:16:21 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Error 113

Yes. In 1.6.1.1 we changed the way the parameters are marshalled and now we found a little bug in this method.

We just uploaded the new version 1.6.1.2 that solves such a bug.

Download it, try and let's know.