RSAPKCS1SignatureFormatter.CreateSignature(Byte[]) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée la signature PKCS #1 RSA pour les données spécifiées.
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()
Paramètres
- rgbHash
- Byte[]
Données à signer.
Retours
Signature numérique pour rgbHash
.
Exceptions
La clé est null
.
- ou -
L’algorithme de hachage a la valeur null
.
Le paramètre rgbHash
a la valeur null
.
Exemples
L’exemple suivant montre comment créer une signature PKCS #1 version 1.5.
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
Remarques
Vous devez spécifier une clé et un algorithme de hachage avant d’appeler cette méthode.