OpenSSL, as well as most other DSA implementations, displays signatures in ASN.1 format. Thus, a 40-byte signature (two 20-byte integers) becomes 46 bytes due to the headers of the ASN.1 structure. (For more details see this forum post )
My question is: how to handle this format in C #? (or elsewhere, for that matter)
I spent some time trying to deal with it using .NET packages System.Security.Crypto, but refused it (it really disappoints because it clearly has internal code to parse ASN.1, since it can read the DER format, but there is no way to use it - but I'm distracted ...)
Then I started working with the BouncyCastle C # library. I can get it in Asn1Object, and if I expand it during debugging, I see that it contains DerSequencewith two integers, but how to get it out (preferably in BigIntegersso that I can feed them DSA.VerifySignature?)
Code example:
Byte[] msgText = ReadFile("test_msg.txt");
Byte[] msgSigRaw = ReadFile("test_sig_1.bin");
Asn1Object sigASN = Asn1Object.FromByteArray(msgSigRaw);
...
X509Certificate implCert = ReadCertificate("pubcert_dsa.cer");
DsaSigner DSA = new DsaSigner();
DSA.Init(false, implCert.GetPublicKey());
...
BigInteger sigIntR, sigIntS;
...
Boolean validSig = DSA.VerifySignature(msgText, sigIntR, sigIntS);
source
share