验证并从PKCS7 base 64字符串提取原始数据

时间:2018-10-29 19:05:16

标签: chilkat

我正在使用以下代码示例从PKCS7 base 64编码的消息中获取原始数据 https://www.example-code.com/nodejs/crypt_opaque_pkcs7_cms_signature.asp

base64编码的消息同时具有数据和签名。

这是我的代码:

    var Response = "base64 string";

var cert = new chilkat.Cert();    
var success = cert.LoadFromFile("/path/to/abc.cer");
if (success !== true) {
    console.log(cert.LastErrorText);
    console.log("Certificate Load Failed.");    
}

var vCrypt = new chilkat.Crypt2();
success = vCrypt.SetVerifyCert(cert);
if (success !== true) {
  console.log(vCrypt.LastErrorText);
  console.log("SetVerifyCert Failed.");
}

vCrypt.EncodingMode = "base64";
vCrypt.Charset = "utf-8";

var extractedData = vCrypt.OpaqueVerifyStringENC(anbResponse);
if (vCrypt.LastMethodSuccess !== true) {
  console.log(vCrypt.LastErrorText);
  console.log("OpaqueVerifyStringENC Failed.");
}
else{
    console.log("The extracted data: " + extractedData);
}

出现以下错误:

ChilkatLog:
  OpaqueVerifyStringENC:
    DllDate: Aug 25 2018
    ChilkatVersion: 9.5.0.75
    UnlockPrefix: Anything for 30-day trial
    Architecture: Little Endian; 64-bit
    Language: Windows Node.js
    VerboseLogging: 0
    verifyOpaqueSignature:
      loadPkcs7Der:
        der_to_xml:
          ASN data length exceeds remaining number of bytes available.
          tag: 18
          idClass: 0
          bConstructed: 1
          headerLen: 2
          dataLen: 66
          inlen: 64
          Abort ASN.1 processing...
          recursiveDepth: 2
          Abort ASN.1 processing...
          recursiveDepth: 1
        --der_to_xml
        loadPkcs7Xml_inner:
          Expected oid tag for 1st child in PKCS7
        --loadPkcs7Xml_inner
        xml:
        Failed to load PKCS7 XML
      --loadPkcs7Der
      Failed to create PKCS7 from DER.
    --verifyOpaqueSignature
    Failed to verify opaque signature.
  --OpaqueVerifyStringENC
--ChilkatLog

OpaqueVerifyStringENC Failed.

1 个答案:

答案 0 :(得分:0)

如果可以的话,将要传递的base64字符串发布到OpaqueVerifyStringENC。

此外,您可以将base64字符串粘贴到位于https://lapo.it/asn1js/的在线工具中 看看它是否也无法解码并读取生成的ASN.1