【问题标题】:(Node.js) Create Egypt ITIDA CAdES-BES Signature with Automatic JSON Canonicalization(Node.js) 使用自动 JSON 规范化创建埃及 ITIDA CAdES-BES 签名
【发布时间】:2022-06-28 17:52:11
【问题描述】:

我正在使用一个示例(Node.js 创建埃及 ITIDA CAdES-BES 签名与自动 JSON 规范化)但我总是收到此错误(4043 4043:message-digest 属性值与计算值不匹配[message-摘要属性值与计算值不匹配])。

你能帮我解决一下吗?

使用的代码:

 // This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

var crypt = new chilkat.Crypt2();
crypt.VerboseLogging = true;

var cert = new chilkat.Cert();
cert.VerboseLogging = true;

// Set the smart card PIN, which will be needed for signing.
cert.SmartCardPin = "12345678";

// There are many ways to load the certificate.  
// This example was created for a customer using an ePass2003 USB token.
// Assuming the USB token is the only source of a hardware-based private key..
var success = cert.LoadFromSmartcard("");
if (success !== true) {
    console.log(cert.LastErrorText);
    return;
}

// Tell the crypt class to use this cert.
success = crypt.SetSigningCert(cert);
if (success !== true) {
    console.log(crypt.LastErrorText);
    return;
}

var cmsOptions = new chilkat.JsonObject();
// Setting "DigestData" causes OID 1.2.840.113549.1.7.5 (digestData) to be used.
cmsOptions.UpdateBool("DigestData",true);
cmsOptions.UpdateBool("OmitAlgorithmIdNull",true);

// Indicate that we are passing normal JSON and we want Chilkat do automatically
// do the ITIDA JSON canonicalization:
cmsOptions.UpdateBool("CanonicalizeITIDA",true);

crypt.CmsOptions = cmsOptions.Emit();

// The CadesEnabled property applies to all methods that create CMS/PKCS7 signatures. 
// To create a CAdES-BES signature, set this property equal to true. 
crypt.CadesEnabled = true;

crypt.HashAlgorithm = "sha256";

var jsonSigningAttrs = new chilkat.JsonObject();
jsonSigningAttrs.UpdateInt("contentType",1);
jsonSigningAttrs.UpdateInt("signingTime",1);
jsonSigningAttrs.UpdateInt("messageDigest",1);
jsonSigningAttrs.UpdateInt("signingCertificateV2",1);
crypt.SigningAttributes = jsonSigningAttrs.Emit();

// By default, all the certs in the chain of authentication are included in the signature.
// If desired, we can choose to only include the signing certificate:
crypt.IncludeCertChain = false;


var jsonToSign = "{ ... }";

// Create the CAdES-BES signature.
crypt.EncodingMode = "base64";

// Make sure we sign the utf-8 byte representation of the JSON string
crypt.Charset = "utf-8";

var sigBase64 = crypt.SignStringENC(jsonToSign);
if (crypt.LastMethodSuccess == false) {
    console.log(crypt.LastErrorText);
    return;
}

console.log("Base64 signature:");
console.log(sigBase64);

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: node.js digital-signature asn.1 pkcs#7 chilkat


【解决方案1】:

【讨论】:

  • 好的,现在我在博客中读到你提到我尝试“创建 ITIDA 签名 JSON 并发送到 ETA(埃及税务局)门户”,但我得到这个响应响应状态代码:400 响应正文:{ “错误”:{“代码”:“验证错误”,“消息”:空,“目标”:空,“详细信息”:[{“代码”:“提交”,“目标”:“提交”,“消息” :“无效的结构化提交。有关更多详细信息,请使用相关 ID 联系系统管理员:0HMHR7GAN3E9F:0000000B”} ] } }
  • 我使用这个工具来生成 json tools.chilkat.io/Default.cshtml ,就像你在例子中提到的那样
  • 有什么建议吗? @ChilkatSoftware
【解决方案2】:

有关调试的详细信息以及可以发送给 Chilkat 的内容,请参阅此示例:https://www.example-code.com/nodejs/itida_egypt_debug.asp

【讨论】:

    【解决方案3】:

    我们遇到了这个错误,直到我们被告知不要在 json 文件中使用任何空值。所以,请尝试用“”替换json文件中的任何空值。

    【讨论】:

      猜你喜欢
      • 2022-07-13
      • 2015-01-09
      • 2020-06-16
      • 1970-01-01
      • 2014-01-20
      • 2019-05-07
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      相关资源
      最近更新 更多