You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use pkcs11js with Thales Luna HSM. Works fine with AES_CBC, but getting it to work with AES_GCM is giving me some trouble.
I think the issue could be with the IV parameter, but I am not sure.
With Luna, IV can not be provided to the HSM, but the HSM generates it. in C, I can get it working by just setting pointer of IV in CK_GCM_PARAMS to NULL params.pIv = NULL;
The error I get which is triggered just after C_EcryptInit is:
TypeError: Argument 1 has wrong type. Property 'type' should be a Number
at PKCS11.C_EncryptInit (/home/e143810/nodejs/node_modules/pkcs11js/index.js:77:22)
at Object.<anonymous> (/home/e143810/nodejs/f_encrypt_AES128GCM.js:85:12)
The code I am using is quite basic:
/**
* Your app code here
*/
var template = [
{ type: pkcs11js.CKA_CLASS, value: pkcs11js.CKO_SECRET_KEY },
{ type: pkcs11js.CKA_TOKEN, value: false },
{ type: pkcs11js.CKA_LABEL, value: "My AES Key2" },
{ type: pkcs11js.CKA_VALUE_LEN, value: 256 / 8 },
{ type: pkcs11js.CKA_ENCRYPT, value: true },
{ type: pkcs11js.CKA_DECRYPT, value: true },
];
var secretKey = pkcs11.C_GenerateKey(session, { mechanism: pkcs11js.CKM_AES_KEY_GEN }, template);
console.log("key handle:",secretKey.toJSON());
// Generate AES GCM parameters
// Generate random IV and setup IV params
//var iv = pkcs11.C_GenerateRandom(session, new Buffer.alloc(12));
var iv = new Buffer.alloc(32);
// Generate Additional Authentication Data(AAD) bytes
var aad = new Buffer.from("AAAD");
// Generate iv bits size
var ivBits = 12*8;//96
// Generate tag bits size
var tagBits = 128;
var type = 3;//MechParams.AesGCM;
console.log("MechParams.AesGCM=",3);//MechParams.AesGCM);
var gcm_params = {
iv,
ivBits: iv.length * 8,
aad: aad,
aadBits: aad.length * 8,
tagBits,
};
pkcs11.C_EncryptInit(
session,
{
mechanism: pkcs11js.CKM_AES_GCM,
parameter: gcm_params
},
secretKey
);
The text was updated successfully, but these errors were encountered:
I am trying to use pkcs11js with Thales Luna HSM. Works fine with AES_CBC, but getting it to work with AES_GCM is giving me some trouble.
I think the issue could be with the IV parameter, but I am not sure.
With Luna, IV can not be provided to the HSM, but the HSM generates it. in C, I can get it working by just setting pointer of IV in CK_GCM_PARAMS to NULL
params.pIv = NULL;
The error I get which is triggered just after C_EcryptInit is:
The code I am using is quite basic:
The text was updated successfully, but these errors were encountered: