public bool Verify(byte[] data, byte[] signature, string publicKey) { var key = PublicKeyFactory.CreateKey(Convert.FromBase64String(publicKey)); var dsaDigestSigner = new DsaDigestSigner(new DsaSigner(), new Sha1Digest()); dsaDigestSigner.Init(false, key); dsaDigestSigner.BlockUpdate(data, 0, data.Length); return(dsaDigestSigner.VerifySignature(signature)); }
/// <summary> /// Verifies a signature to be authentic /// </summary> /// <param name="originalSignature">The signature which is be verified</param> /// <param name="publicKey">the public key used for the verification</param> /// <param name="data">the data which is signed</param> /// <returns>true if signature is authentic, false if not</returns> public bool Verify(byte[] originalSignature, byte[] publicKey, byte[] data) { var signer = new DsaDigestSigner(new DsaSigner(), new Sha1Digest()); DsaPublicKeyParameters pubKey = null; try { pubKey = (DsaPublicKeyParameters)CreateAsymmetricKeyParameterFromPublicKeyInfo(publicKey); } catch (Exception exception) { string message = "Public Key Creation Failure!\n" + $"{exception.Message}.\n" + $"The public key file is corrupted, verify public key file or try another key.\n" + $"If all fails create a new key pair."; throw new CryptoException(message, exception); } signer.Init(false, pubKey); signer.BlockUpdate(data, 0, data.Length); return(signer.VerifySignature(originalSignature)); }