繁体   English   中英

(Node.js) 使用自动 JSON 规范化创建埃及 ITIDA CAdES-BES 签名

[英](Node.js) Create Egypt ITIDA CAdES-BES Signature with Automatic JSON Canonicalization

我正在使用一个示例(Node.js Create Egypt ITIDA CAdES-BES Signature with Automatic JSON Canonicalization)但我总是收到此错误( 4043 4043:message-digest 属性值与计算值不匹配[message-digest 属性值不匹配计算值] )。

你能帮我解决问题吗?

使用的代码:

 // 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);

检查此 Chilkat 博客文章中的信息是否有帮助: https ://cknotes.com/itida-4043message-digest-attribute-value-does-not-match-calculated-value/

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM