Freigeben über


RSAPKCS1SignatureFormatter.CreateSignature(Byte[]) Methode

Definition

Erstellt die RSA PKCS #1-Signatur für die angegebenen Daten.

public:
 override cli::array <System::Byte> ^ CreateSignature(cli::array <System::Byte> ^ rgbHash);
public override byte[] CreateSignature (byte[] rgbHash);
override this.CreateSignature : byte[] -> byte[]
Public Overrides Function CreateSignature (rgbHash As Byte()) As Byte()

Parameter

rgbHash
Byte[]

Die zu signierenden Daten.

Gibt zurück

Byte[]

Die digitale Signatur für rgbHash.

Ausnahmen

Der Schlüssel ist null.

- oder -

Der Hashalgorithmus ist null.

Der rgbHash-Parameter ist null.

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie Sie eine PKCS #1 Version 1.5-Signatur erstellen.

using System;
using System.Security.Cryptography;

class RSASample
{

    static void Main()
    {
        try
        {
            //Create a new instance of RSA.
            using (RSA rsa = RSA.Create())
            {
                //The hash to sign.
                byte[] hash;
                using (SHA256 sha256 = SHA256.Create())
                {
                    byte[] data = new byte[] { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 };
                    hash = sha256.ComputeHash(data);
                }

                //Create an RSASignatureFormatter object and pass it the 
                //RSA instance to transfer the key information.
                RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(rsa);

                //Set the hash algorithm to SHA256.
                RSAFormatter.SetHashAlgorithm("SHA256");

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

Friend Class RSASample

    Shared Sub Main()
        Try
            'Create a new instance of RSA.
            Using rsa As RSA = RSA.Create()
                'The hash to sign.
                Dim hash() As Byte
                Using sha256 As SHA256 = SHA256.Create()
                    Dim data() As Byte = { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 }
                    hash = sha256.ComputeHash(data)
                End Using

                'Create an RSASignatureFormatter object and pass it the 
                'RSA to transfer the key information.
                Dim RSAFormatter As New RSAPKCS1SignatureFormatter(rsa)

                'Set the hash algorithm to SHA256.
                RSAFormatter.SetHashAlgorithm("SHA256")

                'Create a signature for HashValue and return it.
                Dim SignedHash() As Byte = RSAFormatter.CreateSignature(hash)
            End Using

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

End Class

Hinweise

Sie müssen einen Schlüssel und einen Hashalgorithmus angeben, bevor Sie diese Methode aufrufen.

Gilt für:

Weitere Informationen