【问题标题】:Digital Signature Verification using BouncyCastle - ECDSA with SHA 256, C#使用 BouncyCastle 进行数字签名验证 - 带有 SHA 256、C# 的 ECDSA
【发布时间】:2012-09-04 12:35:33
【问题描述】:

以下是我的场景 - 我从条形码中读取数据并将其转换为纯文本。此文本是条码数据+数字签名的组合。数字签名附加在末尾,这使我能够分离出实际数据和数字签名数据。数字签名数据使用 sha256 进行哈希处理 -用户向我发送一个公钥作为 Windows 证书文件 (.cer extension)。

必需的实现: - 需要从证书中提取公钥,并根据条形码数据和提供的数字签名验证公钥。

这是我试图用来验证签名的代码

//Note : 
//1.  certPath : is the path where my certificate is located 
//2. GetStreamdata  get the stream of data from the certificate. 

//Get the certificate data here 
                Org.BouncyCastle.X509.X509Certificate cert1 = new X509CertificateParser().ReadCertificate(GetStreamData(cerPath)); 
//get the public key 
                ECPublicKeyParameters ecPublic = (ECPublicKeyParameters)cert1.GetPublicKey(); 
//create a signerutility with type SHA-256withECDSA 
                ISigner signer = SignerUtilities.GetSigner("SHA-256withECDSA"); 
//initial signer with the public key 
                signer.Init(false, ecPublic); 
//get signature in bytes : digitalsignature parameter contains signature that should be used. 
                byte[] dBytes = encoding.GetBytes(digitalsignature); 
//block/finalise update to signer : data : is the actual data. 
                signer.BlockUpdate(data, 0, data.Length); 
                    try 
                    { 
//verify signature 
                         verified =  signer.VerifySignature(dBytes); 
                    } 
                catch(Exception ex) 
                    { 
                        _log.LogException(ex); 
                    } 

我能做到的是:使用充气城堡库提取公众

问题:

Exception thrown on signer.verifysignature
  Message=Unable to cast object of type 'Org.BouncyCastle.Asn1.DerApplicationSpecific' to type 'Org.BouncyCastle.Asn1.Asn1Sequence'. 
  Source=BouncyCastle.Crypto 

【问题讨论】:

    标签: c# bouncycastle


    【解决方案1】:

    问题是我必须在 iso-8859-1 中编码数字签名值。我以前是用 ASCII 编码的。 这解决了问题,我能够验证签名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-16
      • 2020-08-22
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      相关资源
      最近更新 更多