Hello,
I am currently facing an issue while attempting to generate a digital signature using a private key that is attached to a certificate. I have been using the following code snippet successfully for some time:
var signer = cert.createSigner({
certId: certId,
algorithm: cert.HashAlg.SHA256,
});
signer.update(hashedInvoice);
var digitalSignature = signer.sign();
However, suddenly the process stopped working and I am encountering the following error message:
{
"type": "error.SuiteScriptError",
"name": "SIGNING_ERROR",
"message": "An error has occurred during digital signature generation.",
"id": "",
"stack": [
"createError(N/error)",
"signDocument(/SuiteScripts/_az_einv_sa_testsignature.js:57)",
"afterSubmit(/SuiteScripts/_az_einv_sa_testsignature.js:9)"
],
"cause": {
"type": "internal error",
"code": "SIGNING_ERROR",
"details": "An error has occurred during digital signature generation.",
"userEvent": "aftersubmit",
"stackTrace": [
"createError(N/error)",
"signDocument(/SuiteScripts/_az_einv_sa_testsignature.js:57)",
"afterSubmit(/SuiteScripts/_az_einv_sa_testsignature.js:9)"
],
"notifyOff": false
},
"notifyOff": false,
"userFacing": false
}
I would greatly appreciate your assistance in identifying the root cause of this issue and helping me resolve it. Could you please review the provided code snippet and error message to determine if there is something wrong with the way I am generating the digital signature using the attached private key?
Additionally, I came across an alternative approach to generating a digital signature using a private key:
var hmac = crypto.createHmac({
algorithm: crypto.HashAlg.SHA256,
key: privateKey
});
hmac.update({ input: dataToSign, inputEncoding: crypto.Encoding.UTF_8 });
var generatedSignature = hmac.digest({ outputEncoding: crypto.Encoding.HEX });
Thank you very much for your attention and support. I look forward to your prompt response.