次の方法で共有


DSACryptoServiceProvider.VerifySignature メソッド

指定したデータに対する DSA 署名を検証します。

Overrides Public Function VerifySignature( _
   ByVal rgbHash() As Byte, _   ByVal rgbSignature() As Byte _) As Boolean
[C#]
public override bool VerifySignature(byte[] rgbHash,byte[] rgbSignature);
[C++]
public: bool VerifySignature(unsigned charrgbHash __gc[],unsigned charrgbSignature __gc[]);
[JScript]
public override function VerifySignature(
   rgbHash : Byte[],rgbSignature : Byte[]) : Boolean;

パラメータ

  • rgbHash
    rgbSignature で署名したデータ。
  • rgbSignature
    rgbData に対して検証される署名。

戻り値

rgbSignature が、指定したハッシュ アルゴリズムとキーを使用して rgbHash に対して算出された署名と一致する場合は true 。それ以外の場合は false

使用例

[Visual Basic, C#] VerifySignature メソッドを使用する方法を次の例に示します。

 
Imports System.Security.Cryptography
Imports System.Text

Module RSACSPExample

    Sub Main()
        Try
            'Create a UnicodeEncoder to convert between byte array and string.
            Dim ByteConverter As New ASCIIEncoding

            Dim dataString As String = "Data to Sign"

            'Create byte arrays to hold original, encrypted, and decrypted data.
            Dim dataToSign As Byte() = ByteConverter.GetBytes(dataString)
            Dim hashedData() As Byte
            Dim signedData() As Byte

            ' Create a SHA1CryptoServiceProvider object 
            ' to hash the data that will be signed.
            Dim SHA1alg As New SHA1CryptoServiceProvider

            ' Hash the data to sign.
            hashedData = SHA1alg.ComputeHash(dataToSign)

            'Create a new instance of the DSACryptoServiceProvider class 
            ' and automatically create a new key-pair.
            Dim DSAalg As New DSACryptoServiceProvider

            'Use the MapNameToOID method to get an object identifier  
            '(OID) from the string name of the SHA1 algorithm.
            Dim OID As String = CryptoConfig.MapNameToOID("SHA1")

            ' Sign the hash and pass the OID.
            signedData = DSAalg.SignHash(hashedData, OID)

            ' Verify the signature and display the results to the
            ' console.
            If DSAalg.VerifySignature(hashedData, signedData) Then
                Console.WriteLine("The data was verified.")
            Else
                Console.WriteLine("The data does not match the signature.")
            End If

        Catch e As CryptographicException
            'Catch this exception in case the encryption did
            'not succeed.
            Console.WriteLine(e.Message)
        End Try
    End Sub

End Module

[C#] 
using System;
using System.Security.Cryptography;
using System.Text;

class DSACSPSample
{
    static void Main()
    {
        try
        {
            //Create a UnicodeEncoder to convert between byte array and string.
            ASCIIEncoding ByteConverter = new ASCIIEncoding();

            string dataString = "Data to Sign";

            //Create byte arrays to hold original, encrypted, and decrypted data.
            byte[] dataToSign = ByteConverter.GetBytes(dataString);
            byte[] hashedData;
            byte[] signedData;

            // Create a SHA1CryptoServiceProvider object 
            // to hash the data that will be signed.
            SHA1CryptoServiceProvider SHA1alg = new SHA1CryptoServiceProvider();

            // Hash the data to sign.
            hashedData = SHA1alg.ComputeHash(dataToSign);

            //Create a new instance of the DSACryptoServiceProvider class 
            // and automatically create a new key-pair.
            DSACryptoServiceProvider DSAalg = new DSACryptoServiceProvider();

            //Use the MapNameToOID method to get an object identifier  
            //(OID) from the string name of the SHA1 algorithm.
            string OID = CryptoConfig.MapNameToOID("SHA1");
 
            // Sign the hash and pass the OID.
            signedData = DSAalg.SignHash(hashedData, OID);

            // Verify the signature and display the results to the
            // console.
            if(DSAalg.VerifySignature(hashedData, signedData))
            {
                Console.WriteLine("The data was verified.");
            }
            else
            {
                Console.WriteLine("The data does not match the signature.");
            }

        }
        catch(CryptographicException e)
        {
            //Catch this exception in case the encryption did
            //not succeed.
            Console.WriteLine(e.Message);

        }
    }
}

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DSACryptoServiceProvider クラス | DSACryptoServiceProvider メンバ | System.Security.Cryptography 名前空間 | 暗号サービス