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

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

DSACryptoServiceProvider.SignHash メソッド

指定したハッシュ値秘密キー暗号化することにより、そのハッシュ値署名計算します

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

Public Function SignHash ( _
    rgbHash As Byte(), _
    str As String _
) As Byte()
Dim instance As DSACryptoServiceProvider
Dim rgbHash As Byte()
Dim str As String
Dim returnValue As Byte()

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

パラメータ

rgbHash

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

str

データハッシュ値作成するために使用するハッシュ アルゴリズムの名前。

戻り値
指定したハッシュ値対すDSA 署名

例外例外
例外種類条件

ArgumentNullException

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

CryptographicException

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

または

秘密キーがありません。

解説解説
使用例使用例

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 hash to sign.
            Dim Hash As Byte()
 = {59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213,
 134, 130, 135}

            'Use the MapNameToOID method to get an OID 
            'for the SHA1 algorithm.
            Dim OID As String
 = CryptoConfig.MapNameToOID("SHA1")

            'The value to hold the signed hash.
            Dim SignedHashValue As Byte()
 = DSASignHash(Hash, DSA.ExportParameters(True), OID)

            'Verify the hash and display the results.
            If DSAVerifyHash(Hash, SignedHashValue, DSA.ExportParameters(False),
 OID) 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
 DSASignHash(ByVal HashToSign() As Byte,
 ByVal DSAKeyInfo As DSAParameters, ByVal HashOID As String) As
 Byte()
        Try
            'Create a new instance of DSACryptoServiceProvider.
            Dim DSA As New
 DSACryptoServiceProvider()

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

            'Sign the hash and return it.
            Return DSA.SignHash(HashToSign, HashOID)
        Catch e As CryptographicException
            Console.WriteLine(e)

            Return Nothing
        End Try
    End Function


    Public Shared Function
 DSAVerifyHash(ByVal Hash() As Byte,
 ByVal SignedHash() As Byte, ByVal DSAKeyInfo As DSAParameters, ByVal
 HashOID As String) 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.VerifyHash(Hash, HashOID, SignedHash)

        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 hash to sign.
            byte[] Hash = {59,4,248,102,77,97,142,201,210,12,224,93,25,41,100,197
,213,134,130,135};
            
            //Use the MapNameToOID method to get an OID 
            //for the SHA1 algorithm.
            string OID = CryptoConfig.MapNameToOID("SHA1");
            
            //The value to hold the signed hash.
            byte[] SignedHashValue = DSASignHash(Hash, DSA.ExportParameters(true),
 OID);

            //Verify the hash and display the results.
            if(DSAVerifyHash(Hash, SignedHashValue, DSA.ExportParameters(false),
 OID))
            {
                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[] DSASignHash(byte[]
 HashToSign, DSAParameters DSAKeyInfo, string HashOID)
    {
        try
        {
            //Create a new instance of DSACryptoServiceProvider.
            DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();

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

            //Sign the hash and return it.
            return DSA.SignHash(HashToSign, HashOID);
        }
        catch(CryptographicException e)
        {
            Console.WriteLine(e);

            return null;
        }

    }

    public static bool DSAVerifyHash(byte[]
 Hash, byte[] SignedHash, DSAParameters DSAKeyInfo, string HashOID)
    {
        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.VerifyHash(Hash, HashOID, SignedHash);

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

            return false;
        }
            
    }

}
#using <System.dll>

using namespace System;
using namespace System::Security::Cryptography;
array<Byte>^ DSASignHash( array<Byte>^HashToSign, DSAParameters DSAKeyInfo,
 String^ HashOID )
{
   try
   {
      
      //Create a new instance of DSACryptoServiceProvider.
      DSACryptoServiceProvider^ DSA = gcnew DSACryptoServiceProvider;
      
      //Import the key information.   
      DSA->ImportParameters( DSAKeyInfo );
      
      //Sign the hash and return it.
      return DSA->SignHash( HashToSign, HashOID );
   }
   catch ( CryptographicException^ e ) 
   {
      Console::WriteLine( e );
      return nullptr;
   }

}

bool DSAVerifyHash( array<Byte>^Hash, array<Byte>^SignedHash,
 DSAParameters DSAKeyInfo, String^ HashOID )
{
   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->VerifyHash( Hash, HashOID, SignedHash );
   }
   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 hash to sign.
      array<Byte>^Hash = {59,4,248,102,77,97,142,201,210,12,224,93,25,41,100
,197,213,134,130,135};
      
      //Use the MapNameToOID method to get an OID 
      //for the SHA1 algorithm.
      String^ OID = CryptoConfig::MapNameToOID( "SHA1" );
      
      //The value to hold the signed hash.
      array<Byte>^SignedHashValue = DSASignHash( Hash, DSA->ExportParameters(
 true ), OID );
      
      //Verify the hash and display the results.
      if ( DSAVerifyHash( Hash, SignedHashValue, DSA->ExportParameters(
 false ), OID ) )
      {
         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 hash to sign.
            ubyte hash[] =  {59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224,
                93, 25, 41, 100, 197, 213, 134, 130, 135};
            
            // Use the MapNameToOID method to get an oid 
            // for the SHA1 algorithm.
            String oid = CryptoConfig.MapNameToOID("SHA1");
            
            // The value to hold the signed hash.
            ubyte signedHashValue[] = DSASignHash(hash, 
            dsa.ExportParameters(true), oid);
            
            // Verify the hash and display the results.
            if (DSAVerifyHash(hash, signedHashValue, 
                dsa.ExportParameters(false), oid)) {
                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[] DSASignHash(ubyte
 hashToSign[], 
        DSAParameters dsaKeyInfo, String hashOid) 
    {
        try {
            //Create a new instance of DSACryptoServiceProvider.
            DSACryptoServiceProvider dsa =  new DSACryptoServiceProvider();
            
            //Import the key information.   
            dsa.ImportParameters(dsaKeyInfo);
            
            //Sign the hash and return it.
            return dsa.SignHash(hashToSign, hashOid) ;
        }
        catch(CryptographicException e) {
            Console.WriteLine(e);
            return null;
        }
    } //DSASignHash  
        
    public static boolean DSAVerifyHash(ubyte
 hash[], ubyte signedHash[],
        DSAParameters dsaKeyInfo, String hashOid) 
    {
        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.VerifyHash(hash, hashOid, signedHash) ;
        } 
        catch (CryptographicException e) {
            Console.WriteLine(e.get_Message());
            return false ;
        }
    } //DSAVerifyHash
} //DSACSPSample
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DSACryptoServiceProvider クラス
DSACryptoServiceProvider メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS