DSASignatureFormatter.SetHashAlgorithm(String) 메서드

정의

디지털 서명 알고리즘(DSA) 서명 포맷터에 대한 해시 알고리즘을 지정합니다.

public:
 override void SetHashAlgorithm(System::String ^ strName);
public override void SetHashAlgorithm(string strName);
override this.SetHashAlgorithm : string -> unit
Public Overrides Sub SetHashAlgorithm (strName As String)

매개 변수

strName
String

서명 포맷터에 사용할 해시 알고리즘의 이름입니다.

예외

매개 변수가 strName 해시 알고리즘에 SHA1 매핑되지 않습니다.

예제

using System;
using System.Security.Cryptography;

class DSASample
{
        
    static void Main()
    {
        try
        {
            //Create a new instance of DSA.
            DSA DSA = DSA.Create();

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

            //Create an DSASignatureFormatter object and pass it the 
            //DSA instance to transfer the key information.
            DSASignatureFormatter DSAFormatter = new DSASignatureFormatter(DSA);

            //Set the hash algorithm to SHA1.
            DSAFormatter.SetHashAlgorithm("SHA1");

            //Create a signature for HashValue and return it.
            byte[] SignedHash = DSAFormatter.CreateSignature(Hash);
        }
        catch(CryptographicException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
Imports System.Security.Cryptography

 _

Class DSASample


    Shared Sub Main()
        Try
            'Create a new instance of DSA.
            Dim DSA As DSA = DSA.Create()

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

            'Create an DSASignatureFormatter object and pass it the 
            'DSA instance to transfer the key information.
            Dim DSAFormatter As New DSASignatureFormatter(DSA)

            'Set the hash algorithm to SHA1.
            DSAFormatter.SetHashAlgorithm("SHA1")

            'Create a signature for HashValue and return it.
            Dim SignedHash As Byte() = DSAFormatter.CreateSignature(Hash)

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

적용 대상

추가 정보