数字签名验证期间出错:NoSuchFieldError id_TA_ECDSA_SHA_1

时间:2018-03-17 08:39:43

标签: java signature verification digital

我正在使用bcprov-jdk16-1.46.jar和bcmail-jdk16-1.46.jar来验证嵌入在JSON文件中的签名。 代码如下:

try
{
  Security.addProvider(new BouncyCastleProvider());
  InputStream objInputStream= new ByteArrayInputStream(signData);

  CMSSignedData objCMSSignedData =null;
  CMSProcessableByteArray cms_data = new CMSProcessableByteArray(actualData);
  objCMSSignedData= new CMSSignedData(cms_data,objInputStream);

  CertStore certs = objCMSSignedData.getCertificatesAndCRLs("Collection", "BC");
  SignerInformationStore signers = objCMSSignedData.getSignerInfos();
  Collection<?> c = signers.getSigners();
  Iterator<?> it = c.iterator();
  while(it.hasNext()) 
  {
    X509Certificate cert = null;
    SignerInformation signer = (SignerInformation)it.next();
    Collection<?> certCollection = certs.getCertificates(signer.getSID());  
    if(!certCollection.isEmpty())
    {
      for(Iterator<?> certIt = certCollection.iterator(); certIt.hasNext();)
      {
        cert = (X509Certificate)certIt.next();  

        PublicKey publicKey = cert.getPublicKey();
        String str=new String(publicKey.getEncoded());

        String sha256hex = DigestUtils.sha256Hex(new String(Base64.encodeBase64(publicKey.getEncoded())));

        if(verfiyHexadecimalKey(sha256hex,entityid) {//end
          if(signer.verify(publicKey, "BC"))
          {
            verified =true;
            verifyCounter++;
          }
          else{
            verifyCounter=0;
          }
        }
      }
    }
  }
}

在我的一台服务器上执行此代码作为可运行的jar时,我正在

  

&#34; java.lang.NoSuchFieldError:id_TA_ECDSA_SHA_1&#34; at line objCMSSignedData = new CMSSignedData(cms_data,objInputStream);

但是在Eclipse上执行相同的代码时,签名会成功验证 帮助我解决这个问题。

0 个答案:

没有答案