DSACryptoServiceProvider.VerifyData メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DSACryptoServiceProvider.VerifyData メソッドの意味・解説 

DSACryptoServiceProvider.VerifyData メソッド

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

名前空間: System.Security.Cryptography
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function VerifyData ( _
    rgbData As Byte(), _
    rgbSignature As Byte() _
) As Boolean
Dim instance As DSACryptoServiceProvider
Dim rgbData As Byte()
Dim rgbSignature As Byte()
Dim returnValue As Boolean

returnValue = instance.VerifyData(rgbData, rgbSignature)
public bool VerifyData (
    byte[] rgbData,
    byte[] rgbSignature
)
public:
bool VerifyData (
    array<unsigned char>^ rgbData, 
    array<unsigned char>^ rgbSignature
)
public boolean VerifyData (
    byte[] rgbData, 
    byte[] rgbSignature
)
public function VerifyData (
    rgbData : byte[], 
    rgbSignature : byte[]
) : boolean

パラメータ

rgbData

署名されデータ

rgbSignature

検証される署名データ

戻り値
検証結果署名有効な場合trueそれ以外場合false

解説解説
使用例使用例

DSACryptoServiceProvider クラス使用してデータ署名してそのデータ検証するコード例次に示します

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

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;
        }
            
    }

}
#using <System.dll>

using namespace System;
using namespace System::Security::Cryptography;
array<Byte>^ DSASignData( array<Byte>^DataToSign, DSAParameters DSAKeyInfo
 )
{
   try
   {
      
      //Create a new instance of DSACryptoServiceProvider.
      DSACryptoServiceProvider^ DSA = gcnew 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 nullptr;
   }

}

bool DSAVerifyData( array<Byte>^Data, array<Byte>^SignedData,
 DSAParameters DSAKeyInfo )
{
   try
   {
      
      //Create a new instance of DSACryptoServiceProvider.
      DSACryptoServiceProvider^ DSA = gcnew 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 = gcnew DSACryptoServiceProvider;
      
      //The data to sign.
      array<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.
      array<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 );
   }

}

import System.* ;
import System.Security.Cryptography.* ;

class DSACSPSample
{
    public static void main(String[]
 args)
    {
        try {
            // Create a new instance of DSACryptoServiceProvider to
 generate
            // a new key pair.
            DSACryptoServiceProvider dsa =  new DSACryptoServiceProvider();
            
            //The data to sign.
            ubyte 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.
            ubyte 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.get_Message());
        }
    } //main 

    public static ubyte[] DSASignData(ubyte
 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.get_Message());            
            return null ;
        }
    } //DSASignData

    public static boolean DSAVerifyData(ubyte
 data[], ubyte 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.get_Message());
            return false ;
        }
    } //DSAVerifyData
} //DSACSPSample

DSACryptoServiceProvider作成し新しキー ペア生成してから、一部データ署名して、そのデータテストするコード例次に示します

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
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);

        }
    }
}
using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Text;
int main()
{
   try
   {
      
      //Create a UnicodeEncoder to convert between byte array and string.
      ASCIIEncoding^ ByteConverter = gcnew ASCIIEncoding;
      String^ dataString = "Data to Sign";
      
      //Create byte arrays to hold original, encrypted, and decrypted
 data.
      array<Byte>^dataToSign = ByteConverter->GetBytes( dataString );
      array<Byte>^hashedData;
      array<Byte>^signedData;
      
      // Create a SHA1CryptoServiceProvider object 
      // to hash the data that will be signed.
      SHA1CryptoServiceProvider^ SHA1alg = gcnew 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 = gcnew 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 );
   }

}

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DSACryptoServiceProvider クラス
DSACryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス


このページでは「.NET Framework クラス ライブラリ リファレンス」からDSACryptoServiceProvider.VerifyData メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDSACryptoServiceProvider.VerifyData メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDSACryptoServiceProvider.VerifyData メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

DSACryptoServiceProvider.VerifyData メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DSACryptoServiceProvider.VerifyData メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS