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

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

RSACryptoServiceProvider.VerifyHash メソッド

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

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

Public Function VerifyHash ( _
    rgbHash As Byte(), _
    str As String, _
    rgbSignature As Byte() _
) As Boolean
Dim instance As RSACryptoServiceProvider
Dim rgbHash As Byte()
Dim str As String
Dim rgbSignature As Byte()
Dim returnValue As Boolean

returnValue = instance.VerifyHash(rgbHash, str, rgbSignature)
public bool VerifyHash (
    byte[] rgbHash,
    string str,
    byte[] rgbSignature
)
public:
bool VerifyHash (
    array<unsigned char>^ rgbHash, 
    String^ str, 
    array<unsigned char>^ rgbSignature
)
public boolean VerifyHash (
    byte[] rgbHash, 
    String str, 
    byte[] rgbSignature
)
public function VerifyHash (
    rgbHash : byte[], 
    str : String, 
    rgbSignature : byte[]
) : boolean

パラメータ

rgbHash

署名されるデータハッシュ値

str

データハッシュ値作成使用するハッシュ アルゴリズム識別子 (OID)。

rgbSignature

検証される署名データ

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

例外例外
例外種類条件

ArgumentNullException

rgbHash パラメータnull 参照 (Visual Basic では Nothing) です。

または

rgbSignature パラメータnull 参照 (Visual Basic では Nothing) です。

CryptographicException

暗号サービス プロバイダ (CSP) を取得できません。

または

署名検証できません。

解説解説
使用例使用例

一部データ暗号化し、暗号化データハッシュ作成して、そのハッシュデジタル署名署名するコード例次に示します

Imports System
Imports System.Text
Imports System.Security.Cryptography

Namespace RSACryptoServiceProvider_Examples
    Class MyMainClass
        Shared Sub Main()
            Dim toEncrypt() As Byte
            Dim encrypted() As Byte
            Dim signature() As Byte
            'Choose a small amount of data to encrypt.
            Dim original As String
 = "Hello"
            Dim myAscii As New
 ASCIIEncoding()

            'Create a sender and receiver.
            Dim mySender As New
 Sender()
            Dim myReceiver As New
 Receiver()

            'Convert the data string to a byte array.
            toEncrypt = myAscii.GetBytes(original)

            'Encrypt data using receiver's public key.
            encrypted = mySender.EncryptData(myReceiver.PublicParameters, toEncrypt)

            'Hash the encrypted data and generate a signature on the
 hash
            ' using the sender's private key.
            signature = mySender.HashAndSign(encrypted)

            Console.WriteLine("Original: {0}", original)

            'Verify the signature is authentic using the sender's public
 key.
            If myReceiver.VerifyHash(mySender.PublicParameters,
 encrypted, signature) Then
                'Decrypt the data using the receiver's private key.
                myReceiver.DecryptData(encrypted)
            Else
                Console.WriteLine("Invalid signature")
            End If
        End Sub 'Main
    End Class 'MyMainClass

    Class Sender
        Private rsaPubParams As RSAParameters
        Private rsaPrivateParams As RSAParameters

        Public Sub New()
            Dim rsaCSP As New
 RSACryptoServiceProvider()

            'Generate public and private key data.
            rsaPrivateParams = rsaCSP.ExportParameters(True)
            rsaPubParams = rsaCSP.ExportParameters(False)
        End Sub 'New

        Public ReadOnly Property
 PublicParameters() As RSAParameters
            Get
                Return rsaPubParams
            End Get
        End Property

        'Manually performs hash and then signs hashed value.
        Public Function HashAndSign(ByVal
 encrypted() As Byte) As
 Byte()
            Dim rsaCSP As New
 RSACryptoServiceProvider()
            Dim hash As New
 SHA1Managed()
            Dim hashedData() As Byte

            rsaCSP.ImportParameters(rsaPrivateParams)

            hashedData = hash.ComputeHash(encrypted)
            Return rsaCSP.SignHash(hashedData, CryptoConfig.MapNameToOID("SHA1"))
        End Function 'HashAndSign

        'Encrypts using only the public key data.
        Public Function EncryptData(ByVal
 rsaParams As RSAParameters, ByVal toEncrypt()
 As Byte) As Byte()
            Dim rsaCSP As New
 RSACryptoServiceProvider()

            rsaCSP.ImportParameters(rsaParams)
            Return rsaCSP.Encrypt(toEncrypt, False)
        End Function 'EncryptData
    End Class 'Sender

    Class Receiver
        Private rsaPubParams As RSAParameters
        Private rsaPrivateParams As RSAParameters

        Public Sub New()
            Dim rsaCSP As New
 RSACryptoServiceProvider()

            'Generate public and private key data.
            rsaPrivateParams = rsaCSP.ExportParameters(True)
            rsaPubParams = rsaCSP.ExportParameters(False)
        End Sub 'New

        Public ReadOnly Property
 PublicParameters() As RSAParameters
            Get
                Return rsaPubParams
            End Get
        End Property

        'Manually performs hash and then verifies hashed value.
        Public Function VerifyHash(ByVal
 rsaParams As RSAParameters, ByVal signedData()
 As Byte, ByVal signature() As Byte) As Boolean
            Dim rsaCSP As New
 RSACryptoServiceProvider()
            Dim hash As New
 SHA1Managed()
            Dim hashedData() As Byte

            rsaCSP.ImportParameters(rsaParams)

            hashedData = hash.ComputeHash(signedData)
            Return rsaCSP.VerifyHash(hashedData, CryptoConfig.MapNameToOID("SHA1"),
 signature)
        End Function 'VerifyHash

        'Decrypt using the private key data.
        Public Sub DecryptData(ByVal
 encrypted() As Byte)
            Dim fromEncrypt() As Byte
            Dim roundTrip As String
            Dim myAscii As New
 ASCIIEncoding()
            Dim rsaCSP As New
 RSACryptoServiceProvider()

            rsaCSP.ImportParameters(rsaPrivateParams)
            fromEncrypt = rsaCSP.Decrypt(encrypted, False)
            roundTrip = myAscii.GetString(fromEncrypt)

            Console.WriteLine("RoundTrip: {0}", roundTrip)
        End Sub 'DecryptData
    End Class 'Receiver
End Namespace 'RSACryptoServiceProvider_Examples
using System;
using System.Text;
using System.Security.Cryptography;

namespace RSACryptoServiceProvider_Examples
{
    class MyMainClass
    {
        static void Main()
        {
            byte[] toEncrypt;
            byte[] encrypted;
            byte[] signature;
            //Choose a small amount of data to encrypt.
            string original = "Hello";
            ASCIIEncoding myAscii = new ASCIIEncoding();

            //Create a sender and receiver.
            Sender mySender = new Sender();
            Receiver myReceiver = new Receiver();

            //Convert the data string to a byte array.
            toEncrypt = myAscii.GetBytes(original);
            
            //Encrypt data using receiver's public key.
            encrypted = mySender.EncryptData(myReceiver.PublicParameters, toEncrypt);
            
            //Hash the encrypted data and generate a signature on the
 hash
            // using the sender's private key.
            signature = mySender.HashAndSign(encrypted);

            Console.WriteLine("Original: {0}", original);

            //Verify the signature is authentic using the sender's public
 key.
            if(myReceiver.VerifyHash(mySender.PublicParameters,
 encrypted, signature))
            {
                //Decrypt the data using the receiver's private key.
                myReceiver.DecryptData(encrypted);
            }
            else
            {
                Console.WriteLine("Invalid signature");
            }
        }
    }

    class Sender
    {
        RSAParameters rsaPubParams;
        RSAParameters rsaPrivateParams;

        public Sender()
        {
            RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
            
            //Generate public and private key data.
            rsaPrivateParams = rsaCSP.ExportParameters(true);
            rsaPubParams = rsaCSP.ExportParameters(false);
        }
        
        public RSAParameters PublicParameters
        {
            get
            {
                return rsaPubParams;
            }
        }

        //Manually performs hash and then signs hashed value.
        public byte[] HashAndSign(byte[] encrypted)
        {
            RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
            SHA1Managed hash = new SHA1Managed();
            byte[] hashedData;

            rsaCSP.ImportParameters(rsaPrivateParams);

            hashedData = hash.ComputeHash(encrypted);
            return rsaCSP.SignHash(hashedData, CryptoConfig.MapNameToOID("SHA1"));
        }

        //Encrypts using only the public key data.
        public byte[] EncryptData(RSAParameters rsaParams, byte[]
 toEncrypt)
        {
            RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();

            rsaCSP.ImportParameters(rsaParams);
            return rsaCSP.Encrypt(toEncrypt, false);
        }
    }

    class Receiver
    {
        RSAParameters rsaPubParams;
        RSAParameters rsaPrivateParams;

        public Receiver()
        {
            RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
            
            //Generate public and private key data.
            rsaPrivateParams = rsaCSP.ExportParameters(true);
            rsaPubParams = rsaCSP.ExportParameters(false);
        }

        public RSAParameters PublicParameters
        {
            get
            {
                return rsaPubParams;
            }
        }

        //Manually performs hash and then verifies hashed value.
        public bool VerifyHash(RSAParameters
 rsaParams, byte[] signedData, byte[] signature)
        {
            RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
            SHA1Managed hash = new SHA1Managed();
            byte[] hashedData;

            rsaCSP.ImportParameters(rsaParams);

            hashedData = hash.ComputeHash(signedData);
            return rsaCSP.VerifyHash(hashedData, CryptoConfig.MapNameToOID("SHA1"),
 signature);
        }

        //Decrypt using the private key data.
        public void DecryptData(byte[] encrypted)
        {
            byte[] fromEncrypt;
            string roundTrip;
            ASCIIEncoding myAscii = new ASCIIEncoding();
            RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();

            rsaCSP.ImportParameters(rsaPrivateParams);
            fromEncrypt = rsaCSP.Decrypt(encrypted, false);
            roundTrip = myAscii.GetString(fromEncrypt);

            Console.WriteLine("RoundTrip: {0}", roundTrip);
        }
    }
}
#using <System.dll>

using namespace System;
using namespace System::Text;
using namespace System::Security::Cryptography;
ref class Sender
{
private:
   RSAParameters rsaPubParams;
   RSAParameters rsaPrivateParams;

public:
   Sender()
   {
      RSACryptoServiceProvider^ rsaCSP = gcnew RSACryptoServiceProvider;
      
      //Generate public and private key data.
      rsaPrivateParams = rsaCSP->ExportParameters( true );
      rsaPubParams = rsaCSP->ExportParameters( false );
   }


   property RSAParameters PublicParameters 
   {
      RSAParameters get()
      {
         return rsaPubParams;
      }

   }

   //Manually performs hash and then signs hashed value.
   array<Byte>^ HashAndSign( array<Byte>^encrypted )
   {
      RSACryptoServiceProvider^ rsaCSP = gcnew RSACryptoServiceProvider;
      SHA1Managed^ hash = gcnew SHA1Managed;
      array<Byte>^hashedData;
      rsaCSP->ImportParameters( rsaPrivateParams );
      hashedData = hash->ComputeHash( encrypted );
      return rsaCSP->SignHash( hashedData, CryptoConfig::MapNameToOID(
 "SHA1" ) );
   }


   //Encrypts using only the public key data.
   array<Byte>^ EncryptData( RSAParameters rsaParams, array<Byte>^toEncrypt
 )
   {
      RSACryptoServiceProvider^ rsaCSP = gcnew RSACryptoServiceProvider;
      rsaCSP->ImportParameters( rsaParams );
      return rsaCSP->Encrypt( toEncrypt, false
 );
   }

};

ref class Receiver
{
private:
   RSAParameters rsaPubParams;
   RSAParameters rsaPrivateParams;

public:
   Receiver()
   {
      RSACryptoServiceProvider^ rsaCSP = gcnew RSACryptoServiceProvider;
      
      //Generate public and private key data.
      rsaPrivateParams = rsaCSP->ExportParameters( true );
      rsaPubParams = rsaCSP->ExportParameters( false );
   }


   property RSAParameters PublicParameters 
   {
      RSAParameters get()
      {
         return rsaPubParams;
      }

   }

   //Manually performs hash and then verifies hashed value.
   bool VerifyHash( RSAParameters rsaParams, array<Byte>^signedData,
 array<Byte>^signature )
   {
      RSACryptoServiceProvider^ rsaCSP = gcnew RSACryptoServiceProvider;
      SHA1Managed^ hash = gcnew SHA1Managed;
      array<Byte>^hashedData;
      rsaCSP->ImportParameters( rsaParams );
      hashedData = hash->ComputeHash( signedData );
      return rsaCSP->VerifyHash( hashedData, CryptoConfig::MapNameToOID(
 "SHA1" ), signature );
   }


   //Decrypt using the private key data.
   void DecryptData( array<Byte>^encrypted )
   {
      array<Byte>^fromEncrypt;
      String^ roundTrip;
      ASCIIEncoding^ myAscii = gcnew ASCIIEncoding;
      RSACryptoServiceProvider^ rsaCSP = gcnew RSACryptoServiceProvider;
      rsaCSP->ImportParameters( rsaPrivateParams );
      fromEncrypt = rsaCSP->Decrypt( encrypted, false );
      roundTrip = myAscii->GetString( fromEncrypt );
      Console::WriteLine( "RoundTrip: {0}", roundTrip );
   }

};

int main()
{
   array<Byte>^toEncrypt;
   array<Byte>^encrypted;
   array<Byte>^signature;
   
   //Choose a small amount of data to encrypt.
   String^ original = "Hello";
   ASCIIEncoding^ myAscii = gcnew ASCIIEncoding;
   
   //Create a sender and receiver.
   Sender^ mySender = gcnew Sender;
   Receiver^ myReceiver = gcnew Receiver;
   
   //Convert the data string to a byte array.
   toEncrypt = myAscii->GetBytes( original );
   
   //Encrypt data using receiver's public key.
   encrypted = mySender->EncryptData( myReceiver->PublicParameters, toEncrypt
 );
   
   //Hash the encrypted data and generate a signature on the hash
   // using the sender's private key.
   signature = mySender->HashAndSign( encrypted );
   Console::WriteLine( "Original: {0}", original );
   
   //Verify the signature is authentic using the sender's public key.
   if ( myReceiver->VerifyHash( mySender->PublicParameters,
 encrypted, signature ) )
   {
      
      //Decrypt the data using the receiver's private key.
      myReceiver->DecryptData( encrypted );
   }
   else
   {
      Console::WriteLine( "Invalid signature" );
   }
}

package RSACryptoServiceProvider_Examples; 

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

class MyMainClass
{
    public static void main(String[]
 args)
    {
        ubyte toEncrypt[];
        ubyte encrypted[];
        ubyte signature[];

        // Choose a small amount of data to encrypt.
        String original = "Hello";
        ASCIIEncoding myAscii = new ASCIIEncoding();

        // Create a sender and receiver.
        Sender mySender = new Sender();
        Receiver myReceiver = new Receiver();

        // Convert the data string to a byte array.
        toEncrypt = myAscii.GetBytes(original);

        // Encrypt data using receiver's public key.
        encrypted = mySender.EncryptData(myReceiver.get_PublicParameters(),
            toEncrypt);

        // Hash the encrypted data and generate a signature on the hash
        // using the sender's private key.
        signature = mySender.HashAndSign(encrypted);
        Console.WriteLine("Original: {0}", original);

        // Verify the signature is authentic using the sender's public
 key.
        if (myReceiver.VerifyHash(mySender.get_PublicParameters(),
 
                encrypted, signature)) {
            // Decrypt the data using the receiver's private key.
            myReceiver.DecryptData(encrypted);
        }
        else {
            Console.WriteLine("Invalid signature");
        }
    } //main
} //MyMainClass

class Sender
{
    private RSAParameters rsaPubParams;
    private RSAParameters rsaPrivateParams;

    public Sender()
    {
        RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();

        // Generate public and private key data.
        rsaPrivateParams = rsaCSP.ExportParameters(true);
        rsaPubParams = rsaCSP.ExportParameters(false);
    } //Sender

    /** @property 
     */
    public RSAParameters get_PublicParameters()
    {
        return rsaPubParams;
    } //get_PublicParameters

    // Manually performs hash and then signs hashed value.
    public ubyte[] HashAndSign(ubyte encrypted[])
    {
        RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
        SHA1Managed hash = new SHA1Managed();
        ubyte hashedData[];

        rsaCSP.ImportParameters(rsaPrivateParams);
        hashedData = hash.ComputeHash(encrypted);
        return rsaCSP.SignHash(hashedData, CryptoConfig.MapNameToOID("SHA1"));
    } //HashAndSign

    // Encrypts using only the public key data.
    public ubyte[] EncryptData(RSAParameters rsaParams, ubyte
 toEncrypt[])
    {
        RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();

        rsaCSP.ImportParameters(rsaParams);
        return rsaCSP.Encrypt(toEncrypt, false);
    } //EncryptData
} //Sender

class Receiver
{
    private RSAParameters rsaPubParams;
    private RSAParameters rsaPrivateParams;

    public Receiver()
    {
        RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();

        // Generate public and private key data.
        rsaPrivateParams = rsaCSP.ExportParameters(true);
        rsaPubParams = rsaCSP.ExportParameters(false);
    } //Receiver

    /** @property 
     */
    public RSAParameters get_PublicParameters()
    {
        return rsaPubParams;
    } //get_PublicParameters
    
    // Manually performs hash and then verifies hashed value.
    public boolean VerifyHash(RSAParameters rsaParams, 
        ubyte signedData[], ubyte signature[])
    {
        RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
        SHA1Managed hash = new SHA1Managed();
        ubyte hashedData[];

        rsaCSP.ImportParameters(rsaParams);
        hashedData = hash.ComputeHash(signedData);
        return rsaCSP.VerifyHash(hashedData, 
            CryptoConfig.MapNameToOID("SHA1"), signature);
    } //VerifyHash

    // Decrypt using the private key data.
    public void DecryptData(ubyte encrypted[])
    {
        ubyte fromEncrypt[];
        String roundTrip;
        ASCIIEncoding myAscii = new ASCIIEncoding();
        RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();

        rsaCSP.ImportParameters(rsaPrivateParams);
        fromEncrypt = rsaCSP.Decrypt(encrypted, false);
        roundTrip = myAscii.GetString(fromEncrypt);

        Console.WriteLine("RoundTrip: {0}", roundTrip);
    } //DecryptData
} //Receiver   
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RSACryptoServiceProvider クラス
RSACryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS