/// <summary> /// Verifies that the base64 encoded signature is valid by hashing the data and then comparing it by decrypting the signature. /// </summary> /// <param name="data">Data (not hash) to be verified</param> /// <param name="signedData">The signed data as byte array</param> /// <param name="publicKey">Public key that is the RSA pair of the private key that signed the message</param> /// <param name="hashAlgorithm">The algorithm used for signing</param> /// <returns>Return true if data is Verified</returns> /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception> /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields.</exception> public static bool VerifyData(byte[] data, byte[] signedData, X509Certificate2 publicKey, HashAlgorithmName hashAlgorithm) { return(CertificateCrypto.VerifyData(data, signedData, publicKey, hashAlgorithm)); }
/// <summary> /// Verifies that the base64 encoded signature is valid by hashing the data and then comparing it by decrypting the signature. /// </summary> /// <param name="data">Data (not hash) to be verified</param> /// <param name="encodedsiged">The encoded hashed and signed data</param> /// <param name="publicKey">Public key that is the RSA pair of the private key that signed the message</param> /// <param name="hashAlgorithm">The algorithm used for signing</param> /// <returns>Return true if data is Verified</returns> /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception> /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields.</exception> public static bool VerifyData(byte[] data, string encodedSigned, X509Certificate2 publicKey, HashAlgorithmName hashAlgorithm) { byte[] signedData = Convert.FromBase64String(encodedSigned); return(CertificateCrypto.VerifyData(data, signedData, publicKey, hashAlgorithm)); }