public virtual bool VerifySignature(byte[] signature) { try { BigInteger[] rs = encoding.Decode(ecParams.N, signature); return(VerifySignature(rs[0], rs[1])); } catch (Exception) { } return(false); }
/// <returns>true if the internal state represents the signature described in the passed in array.</returns> public virtual bool VerifySignature( byte[] signature) { if (forSigning) { throw new InvalidOperationException("DSADigestSigner not initialised for verification"); } byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); try { BigInteger[] sig = encoding.Decode(GetOrder(), signature); return(dsa.VerifySignature(hash, sig[0], sig[1])); } catch (Exception e) { return(false); } }
public static string GenerateSignature(string InputData, string PrivateKeyPath, string PublicKeyPath) { string s = InputData; // s = "20685b5fbfe1898fbb080b0719acc9ed2f365128627f21ffcc1b1ee27471e69e"; try { IDsaEncoding encoding = StandardDsaEncoding.Instance; var encoder = new ASCIIEncoding(); var bencoder = new Base64Encoder(); //var key = GenerateKeys(128); AsymmetricCipherKeyPair MyKey = getPrivateKeyFromPemFile(PrivateKeyPath); ECPublicKeyParameters pubicKey = getPublicKeyFromPemFile(PublicKeyPath); //var pubicKey = (ECPublicKeyParameters)(MyKey1.Public); var privateKey = (ECPrivateKeyParameters)(MyKey.Private); var signature = GetSignature(s, privateKey); BigInteger[] sig = encoding.Decode(GetOrder(), signature); //System.Numerics.BigInteger sigval = 0; //System.Numerics.BigInteger.TryParse(sig[1].ToString(), out sigval); var finalsignature = sig[0].ToString(16) + sig[1].ToString(16); var signatureOK = VerifySignature(pubicKey, s, signature); if (signatureOK) { return(finalsignature); } else { return(""); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(""); } }