DSACryptoServiceProvider.VerifyData メソッド

指定した署名データを、指定したデータに対して計算された署名と比較することによって検証します。

Public Function VerifyData( _
   ByVal rgbData() As Byte, _   ByVal rgbSignature() As Byte _) As Boolean
[C#]
public bool VerifyData(byte[] rgbData,byte[] rgbSignature);
[C++]
public: bool VerifyData(unsigned charrgbData __gc[],unsigned charrgbSignature __gc[]);
[JScript]
public function VerifyData(
   rgbData : Byte[],rgbSignature : Byte[]) : Boolean;

パラメータ

  • rgbData
    署名されたデータ。
  • rgbSignature
    検証される署名データ。

戻り値

検証の結果、署名が有効な場合は true 。それ以外の場合は false

解説

このメソッドは、 SignData によって生成された DSA デジタル署名を検証します。

DSA は、 SHA1 ハッシュ アルゴリズムを使用します。

使用例

 
Imports System
Imports System.Security.Cryptography

 _

Class DSACSPSample


    Shared Sub Main()
        Try
            'Create a new instance of DSACryptoServiceProvider to generate
            'a new key pair.
            Dim DSA As New DSACryptoServiceProvider()

            'The data to sign.
            Dim Data As Byte() = {59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135}

            'The value to hold the signed value.
            Dim SignedValue As Byte() = DSASignData(Data, DSA.ExportParameters(True))

            'Verify the data and display the results.
            If DSAVerifyData(Data, SignedValue, DSA.ExportParameters(False)) Then
                Console.WriteLine("The hash value was verified.")
            Else
                Console.WriteLine("The hash value was not verified.")
            End If


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


    Public Shared Function DSASignData(ByVal DataToSign() As Byte, ByVal DSAKeyInfo As DSAParameters) As Byte()
        Try
            'Create a new instance of DSACryptoServiceProvider.
            Dim DSA As New DSACryptoServiceProvider()

            'Import the key information.   
            DSA.ImportParameters(DSAKeyInfo)

            'Compute hash value, sign the hash, and return the signed hash.
            Return DSA.SignData(DataToSign)
        Catch e As CryptographicException
            Console.WriteLine(e.Message)

            Return Nothing
        End Try
    End Function


    Public Shared Function DSAVerifyData(ByVal Data() As Byte, ByVal SignedData() As Byte, ByVal DSAKeyInfo As DSAParameters) As Boolean
        Try
            'Create a new instance of DSACryptoServiceProvider.
            Dim DSA As New DSACryptoServiceProvider()

            'Import the key information. 
            DSA.ImportParameters(DSAKeyInfo)

            'Verify the signature and return the result.    
            Return DSA.VerifyData(Data, SignedData)

        Catch e As CryptographicException
            Console.WriteLine(e.Message)

            Return False
        End Try
    End Function
End Class


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

class DSACSPSample
{
        
    static void Main()
    {
        try
        {
            //Create a new instance of DSACryptoServiceProvider to generate
            //a new key pair.
            DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();

            //The data to sign.
            byte[] Data = {59,4,248,102,77,97,142,201,210,12,224,93,25,41,100,197,213,134,130,135};
                
            //The value to hold the signed value.
            byte[] SignedValue = DSASignData(Data, DSA.ExportParameters(true));

            //Verify the data and display the results.
            if(DSAVerifyData(Data, SignedValue, DSA.ExportParameters(false)))
            {
                Console.WriteLine("The hash value was verified.");
            }
            else
            {
                Console.WriteLine("The hash value was not verified.");
            }


        }
        catch(ArgumentNullException e)
        {
            Console.WriteLine(e.Message);
        }
    }

    public static byte[] DSASignData(byte[] DataToSign, DSAParameters DSAKeyInfo)
    {
        try
        {
            //Create a new instance of DSACryptoServiceProvider.
            DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();

            //Import the key information.   
            DSA.ImportParameters(DSAKeyInfo);

            //Compute hash value, sign the hash, and return the signed hash.
            return DSA.SignData(DataToSign);
        }
        catch(CryptographicException e)
        {
            Console.WriteLine(e.Message);

            return null;
        }

    }

    public static bool DSAVerifyData(byte[] Data, byte[] SignedData, DSAParameters DSAKeyInfo)
    {
        try
        {
            //Create a new instance of DSACryptoServiceProvider.
            DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();

            //Import the key information. 
            DSA.ImportParameters(DSAKeyInfo);

            //Verify the signature and return the result.    
            return DSA.VerifyData(Data, SignedData);

        }
        catch(CryptographicException e)
        {
            Console.WriteLine(e.Message);

            return false;
        }
            
    }

}

[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Security::Cryptography;

Byte DSASignData(Byte DataToSign[], DSAParameters DSAKeyInfo) [] {
    try {
        //Create a new instance of DSACryptoServiceProvider.
        DSACryptoServiceProvider* DSA = new DSACryptoServiceProvider();

        //Import the key information.   
        DSA->ImportParameters(DSAKeyInfo);

        //Compute hash value, sign the hash, and return the signed hash.
        return DSA->SignData(DataToSign);
    } catch (CryptographicException* e) {
        Console::WriteLine(e->Message);
        return 0;
    }
}

bool DSAVerifyData(Byte Data[], Byte SignedData[], DSAParameters DSAKeyInfo) {
    try {
        //Create a new instance of DSACryptoServiceProvider.
        DSACryptoServiceProvider* DSA = new DSACryptoServiceProvider();

        //Import the key information. 
        DSA->ImportParameters(DSAKeyInfo);

        //Verify the signature and return the result.    
        return DSA->VerifyData(Data, SignedData);
    } catch (CryptographicException* e) {
        Console::WriteLine(e->Message);
        return false;
    }
}

int main() {
    try {
        //Create a new instance of DSACryptoServiceProvider to generate
        //a new key pair.
        DSACryptoServiceProvider* DSA = new DSACryptoServiceProvider();

        //The data to sign.
        Byte Data[] = {59,4,248,102,77,97,142,201,210,12,224,93,25,41,100,197,213,134,130,135};

        //The value to hold the signed value.
        Byte SignedValue[] = DSASignData(Data, DSA->ExportParameters(true));

        //Verify the data and display the results.
        if (DSAVerifyData(Data, SignedValue, DSA->ExportParameters(false))) {
            Console::WriteLine(S"The hash value was verified.");
        } else {
            Console::WriteLine(S"The hash value was not verified.");
        }
    } catch (ArgumentNullException* e) {
        Console::WriteLine(e->Message);
    }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および 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 名前空間 | 暗号サービス