RSACryptoServiceProvider.VerifyData(Byte[], Object, Byte[]) Metodo

Definizione

Verifica che una firma digitale sia valida determinando il valore hash nella firma usando la chiave pubblica fornita e confrontandola con il valore hash fornito.

public:
 bool VerifyData(cli::array <System::Byte> ^ buffer, System::Object ^ halg, cli::array <System::Byte> ^ signature);
public bool VerifyData (byte[] buffer, object halg, byte[] signature);
override this.VerifyData : byte[] * obj * byte[] -> bool
member this.VerifyData : byte[] * obj * byte[] -> bool
Public Function VerifyData (buffer As Byte(), halg As Object, signature As Byte()) As Boolean

Parametri

buffer
Byte[]

I dati che sono stati firmati.

halg
Object

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

signature
Byte[]

Dati della firma da verificare.

Restituisce

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

Eccezioni

Il valore del parametro halg è null.

Il parametro halg non è un tipo valido.

Esempio

Nell'esempio seguente viene illustrato come usare il VerifyData 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 SignData 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.

Il halg parametro può accettare un Stringoggetto , o HashAlgorithmun Typeoggetto .

Si applica a

Vedi anche