RSAPKCS1SignatureDeformatter.VerifySignature(Byte[], Byte[]) 메서드

정의

지정된 데이터에 대한 RSA PKCS#1 서명을 확인합니다.Verifies the RSA PKCS#1 signature for the specified data.

public:
 override bool VerifySignature(cli::array <System::Byte> ^ rgbHash, cli::array <System::Byte> ^ rgbSignature);
public override bool VerifySignature (byte[] rgbHash, byte[] rgbSignature);
override this.VerifySignature : byte[] * byte[] -> bool
Public Overrides Function VerifySignature (rgbHash As Byte(), rgbSignature As Byte()) As Boolean

매개 변수

rgbHash
Byte[]

rgbSignature로 서명된 데이터입니다.The data signed with rgbSignature.

rgbSignature
Byte[]

rgbHash에 대해 확인할 서명입니다.The signature to be verified for rgbHash.

반환

true가 지정된 해시 알고리즘 및 rgbSignature의 키를 사용하여 계산된 서명과 일치하면 rgbHash이고, 그렇지 않으면 false입니다.true if rgbSignature matches the signature computed using the specified hash algorithm and key on rgbHash; otherwise, false.

예외

키가 null인 경우The key is null.

-또는--or- 해시 알고리즘이 null인 경우The hash algorithm is null.

rgbHash 매개 변수는 null입니다.The rgbHash parameter is null.

-또는--or- rgbSignature 매개 변수는 null입니다.The rgbSignature parameter is null.

예제

다음 예제에서는 VerifySignature 메서드를 사용 하 여 서명을 확인 하는 방법을 보여 줍니다.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()
    {
        try
        {
            //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.
                RSAFormatter.SetHashAlgorithm("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);
                RSADeformatter.SetHashAlgorithm("SHA256");
                //Verify the hash and display the results to the console. 
                if (RSADeformatter.VerifySignature(hash, signedHash))
                {
                    Console.WriteLine("The signature was verified.");
                }
                else
                {
                    Console.WriteLine("The signature was not verified.");
                }
            }
        }
        catch (CryptographicException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
Imports System.Security.Cryptography

Friend Class RSASample

    Shared Sub Main()
        Try
            'Create a new instance of RSACryptoServiceProvider.
            Using rsa As New RSACryptoServiceProvider()
                'The hash to sign.
                Dim hash() As Byte
                Using sha256 As SHA256 = SHA256.Create()
                    Dim data() As 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)
                End Using

                'Create an RSASignatureFormatter object and pass it the 
                'RSACryptoServiceProvider to transfer the key information.
                Dim RSAFormatter As New RSAPKCS1SignatureFormatter(rsa)

                'Set the hash algorithm to SHA256.
                RSAFormatter.SetHashAlgorithm("SHA256")

                'Create a signature for HashValue and return it.
                Dim signedHash() As Byte = RSAFormatter.CreateSignature(hash)
                'Create an RSAPKCS1SignatureDeformatter object and pass it the  
                'RSACryptoServiceProvider to transfer the key information.
                Dim RSADeformatter As New RSAPKCS1SignatureDeformatter(rsa)
                RSADeformatter.SetHashAlgorithm("SHA256")
                'Verify the hash and display the results to the console. 
                If RSADeformatter.VerifySignature(hash, signedHash) Then
                    Console.WriteLine("The signature was verified.")
                Else
                    Console.WriteLine("The signature was not verified.")
                End If
            End Using

        Catch e As CryptographicException
            Console.WriteLine(e.Message)
        End Try
    End Sub

End Class

설명

이 메서드를 호출 하기 전에 키 및 해시 알고리즘을 지정 해야 합니다.You must specify a key and a hash algorithm before calling this method.

적용 대상

추가 정보