RSACryptoServiceProvider.VerifyHash Metodo

Definizione

Verifica che la firma digitale sia valida.

Overload

VerifyHash(Byte[], String, Byte[])

Verifica la validità di una firma digitale confrontando il valore hash della firma determinato tramite la chiave pubblica fornita con il valore hash fornito.

VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding)

Verifica che una firma digitale sia valida determinando il valore hash nella firma tramite l'algoritmo hash e il riempimento specificati e confrontandolo con il valore hash indicato.

VerifyHash(Byte[], String, Byte[])

Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs

Verifica la validità di una firma digitale confrontando il valore hash della firma determinato tramite la chiave pubblica fornita con il valore hash fornito.

public:
 bool VerifyHash(cli::array <System::Byte> ^ rgbHash, System::String ^ str, cli::array <System::Byte> ^ rgbSignature);
public bool VerifyHash (byte[] rgbHash, string str, byte[] rgbSignature);
override this.VerifyHash : byte[] * string * byte[] -> bool
member this.VerifyHash : byte[] * string * byte[] -> bool
Public Function VerifyHash (rgbHash As Byte(), str As String, rgbSignature As Byte()) As Boolean

Parametri

rgbHash
Byte[]

Valore hash dei dati firmati.

str
String

Identificatore algoritmo hash (OID) usato per creare il valore hash dei dati.

rgbSignature
Byte[]

Dati della firma da verificare.

Restituisce

true se la firma è valida; in caso contrario, false.

Eccezioni

Il valore del parametro rgbHash è null.

-oppure-

Il valore del parametro rgbSignature è null.

Non è possibile acquisire il provider del servizio di crittografia (CSP).

-oppure-

Non è possibile verificare la firma.

Esempio

Nell'esempio seguente viene illustrato come usare il VerifyHash metodo per verificare una firma. Questo esempio di codice fa parte di un esempio più grande fornito per il SignHash metodo.

bool VerifyHash( RSAParameters rsaParams, array<Byte>^signedData, array<Byte>^signature )
{
   RSACryptoServiceProvider^ rsaCSP = gcnew RSACryptoServiceProvider;
   SHA1Managed^ hash = gcnew SHA1Managed;
   array<Byte>^hashedData;
   rsaCSP->ImportParameters( rsaParams );
   bool dataOK = rsaCSP->VerifyData(signedData, CryptoConfig::MapNameToOID("SHA1"), signature);
   hashedData = hash->ComputeHash( signedData );
   return rsaCSP->VerifyHash( hashedData, CryptoConfig::MapNameToOID( "SHA1" ), signature );
}
public bool VerifyHash(RSAParameters rsaParams, byte[] signedData, byte[] signature)
{
    RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
    SHA1Managed hash = new SHA1Managed();
    byte[] hashedData;

    rsaCSP.ImportParameters(rsaParams);
    bool dataOK = rsaCSP.VerifyData(signedData, CryptoConfig.MapNameToOID("SHA1"), signature);
    hashedData = hash.ComputeHash(signedData);
    return rsaCSP.VerifyHash(hashedData, CryptoConfig.MapNameToOID("SHA1"), signature);
}
Public Function VerifyHash(ByVal rsaParams As RSAParameters, ByVal signedData() As Byte, ByVal signature() As Byte) As Boolean
    Dim rsaCSP As New RSACryptoServiceProvider()
    Dim hash As New SHA1Managed()
    Dim hashedData() As Byte
    Dim dataOK As Boolean

    rsaCSP.ImportParameters(rsaParams)
    dataOK = rsaCSP.VerifyData(signedData, CryptoConfig.MapNameToOID("SHA1"), signature)
    hashedData = hash.ComputeHash(signedData)
    Return rsaCSP.VerifyHash(hashedData, CryptoConfig.MapNameToOID("SHA1"), signature)
End Function 'VerifyHash

Commenti

Questo metodo verifica la RSA firma digitale prodotta dal SignHash metodo . La firma viene verificata ottenendo il valore hash dalla firma usando la chiave pubblica con cui è stato firmato e confrontando tale valore con il valore hash dei dati forniti.

Gli algoritmi hash validi sono SHA1 e MD5. L'identificatore dell'algoritmo può essere derivato dal nome hash usando il MapNameToOID metodo .

A causa di problemi di collisione con SHA1 e MD5, Microsoft consiglia un modello di sicurezza basato su SHA256 o meglio.

Vedi anche

Si applica a

VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding)

Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs
Source:
RSACryptoServiceProvider.Unix.cs

Verifica che una firma digitale sia valida determinando il valore hash nella firma tramite l'algoritmo hash e il riempimento specificati e confrontandolo con il valore hash indicato.

public:
 override bool VerifyHash(cli::array <System::Byte> ^ hash, cli::array <System::Byte> ^ signature, System::Security::Cryptography::HashAlgorithmName hashAlgorithm, System::Security::Cryptography::RSASignaturePadding ^ padding);
public override bool VerifyHash (byte[] hash, byte[] signature, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.Security.Cryptography.RSASignaturePadding padding);
override this.VerifyHash : byte[] * byte[] * System.Security.Cryptography.HashAlgorithmName * System.Security.Cryptography.RSASignaturePadding -> bool
Public Overrides Function VerifyHash (hash As Byte(), signature As Byte(), hashAlgorithm As HashAlgorithmName, padding As RSASignaturePadding) As Boolean

Parametri

hash
Byte[]

Valore hash dei dati firmati.

signature
Byte[]

Dati della firma da verificare.

hashAlgorithm
HashAlgorithmName

Nome dell'algoritmo hash usato per creare il valore hash.

padding
RSASignaturePadding

Riempimento.

Restituisce

true se la firma è valida; in caso contrario, false.

Eccezioni

hashAlgorithm è null o Empty.

hash è null.

-oppure-

padding è null.

padding non è uguale a Pkcs1.

Si applica a