RSAPKCS1SignatureDeformatter.VerifySignature Method (Byte[], Byte[])


Verifies the RSA PKCS#1 signature for the specified data.

Namespace:   System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

public override bool VerifySignature(
	byte[] rgbHash,
	byte[] rgbSignature


Type: System.Byte[]

The data signed with rgbSignature.

Type: System.Byte[]

The signature to be verified for rgbHash.

Return Value

Type: System.Boolean

true if rgbSignature matches the signature computed using the specified hash algorithm and key on rgbHash; otherwise, false.

Exception Condition

The key is null.


The hash algorithm is null.


The rgbHash parameter is null.


The rgbSignature parameter is null.

You must specify a key and a hash algorithm before calling this method.

The following example demonstrates how to use the VerifySignature method to verify a signature.

using System;
using System.Security.Cryptography;

class RSASample

    static void Main()
            //Create a new instance of RSACryptoServiceProvider.
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
                //The hash to sign.
                byte[] hash;
                using (SHA256 sha256 = SHA256.Create())
                    byte[] data = new byte[] { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 };
                    hash = sha256.ComputeHash(data);

                //Create an RSASignatureFormatter object and pass it the 
                //RSACryptoServiceProvider to transfer the key information.
                RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(rsa);

                //Set the hash algorithm to SHA256.

                //Create a signature for HashValue and return it.
                byte[] signedHash = RSAFormatter.CreateSignature(hash);
                //Create an RSAPKCS1SignatureDeformatter object and pass it the  
                //RSACryptoServiceProvider to transfer the key information.
                RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(rsa);
                //Verify the hash and display the results to the console. 
                if (RSADeformatter.VerifySignature(hash, signedHash))
                    Console.WriteLine("The signature was verified.");
                    Console.WriteLine("The signature was not verified.");

        catch (CryptographicException e)


.NET Framework
Available since 1.1
Windows Phone Silverlight
Available since 7.1
Return to top