RSAPKCS1SignatureDeformatter Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Verifica uma RSA assinatura PKCS #1 versão 1.5.
public ref class RSAPKCS1SignatureDeformatter : System::Security::Cryptography::AsymmetricSignatureDeformatter
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public class RSAPKCS1SignatureDeformatter : System.Security.Cryptography.AsymmetricSignatureDeformatter
public class RSAPKCS1SignatureDeformatter : System.Security.Cryptography.AsymmetricSignatureDeformatter
[System.Runtime.InteropServices.ComVisible(true)]
public class RSAPKCS1SignatureDeformatter : System.Security.Cryptography.AsymmetricSignatureDeformatter
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
type RSAPKCS1SignatureDeformatter = class
inherit AsymmetricSignatureDeformatter
type RSAPKCS1SignatureDeformatter = class
inherit AsymmetricSignatureDeformatter
[<System.Runtime.InteropServices.ComVisible(true)>]
type RSAPKCS1SignatureDeformatter = class
inherit AsymmetricSignatureDeformatter
Public Class RSAPKCS1SignatureDeformatter
Inherits AsymmetricSignatureDeformatter
- Herança
- Atributos
Exemplos
O exemplo seguinte demonstra como usar o VerifySignature método para verificar uma assinatura.
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);
//Create an RSAPKCS1SignatureDeformatter object and pass it the
//RSA instance to transfer the key information.
RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(rsa);
RSADeformatter.SetHashAlgorithm("SHA256");
//Verify the hash and display the results to the console.
if (RSADeformatter.VerifySignature(hash, signedHash))
{
Console.WriteLine("The signature was verified.");
}
else
{
Console.WriteLine("The signature was not verified.");
}
}
}
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 instance 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)
'Create an RSAPKCS1SignatureDeformatter object and pass it the
'RSA instance to transfer the key information.
Dim RSADeformatter As New RSAPKCS1SignatureDeformatter(rsa)
RSADeformatter.SetHashAlgorithm("SHA256")
'Verify the hash and display the results to the console.
If RSADeformatter.VerifySignature(hash, signedHash) Then
Console.WriteLine("The signature was verified.")
Else
Console.WriteLine("The signature was not verified.")
End If
End Using
Catch e As CryptographicException
Console.WriteLine(e.Message)
End Try
End Sub
End Class
Observações
Esta classe é usada para verificar uma assinatura digital feita com o RSA algoritmo.
Use RSAPKCS1SignatureFormatter para criar assinaturas digitais com o RSA algoritmo.
Construtores
| Name | Description |
|---|---|
| RSAPKCS1SignatureDeformatter() |
Inicializa uma nova instância da RSAPKCS1SignatureDeformatter classe. |
| RSAPKCS1SignatureDeformatter(AsymmetricAlgorithm) |
Inicializa uma nova instância da RSAPKCS1SignatureDeformatter classe com a chave especificada. |
Métodos
| Name | Description |
|---|---|
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| GetHashCode() |
Serve como função de hash predefinida. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| SetHashAlgorithm(String) |
Define o algoritmo de hash para verificar a assinatura. |
| SetKey(AsymmetricAlgorithm) |
Define a chave pública para verificar a assinatura. |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |
| VerifySignature(Byte[], Byte[]) |
Verifica a RSA assinatura PKCS#1 para os dados especificados. |
| VerifySignature(HashAlgorithm, Byte[]) |
Verifica a assinatura a partir do valor hash especificado. (Herdado de AsymmetricSignatureDeformatter) |