RSACryptoServiceProvider.VerifyHash 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
驗證數位簽章的有效性。
多載
| 名稱 | Description |
|---|---|
| VerifyHash(Byte[], String, Byte[]) |
透過利用提供的公鑰確定簽章中的雜湊值,並與所提供的雜湊值比較,驗證數位簽章的有效性。 |
| VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding) |
透過使用指定的雜湊演算法與填充來確定簽名中的雜湊值,並與所提供的雜湊值比較,驗證數位簽章的有效性。 |
VerifyHash(Byte[], String, Byte[])
透過利用提供的公鑰確定簽章中的雜湊值,並與所提供的雜湊值比較,驗證數位簽章的有效性。
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
參數
- rgbHash
- Byte[]
簽名資料的雜湊值。
- str
- String
用於產生資料雜湊值的雜湊演算法識別碼(OID)。
- rgbSignature
- Byte[]
簽名資料待驗證。
傳回
true如果簽名有效;否則,。 false
例外狀況
範例
以下範例說明如何使用此 VerifyHash 方法驗證簽名。 此程式碼範例是該方法更大範例 SignHash 的一部分。
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
備註
此方法驗證該RSA方法產生的SignHash數位簽章。 透過使用簽名所簽署的公鑰取得雜湊值,並將該值與所提供資料的雜湊值比較來驗證。
有效的雜湊演算法為 SHA1 和 MD5。 演算法識別碼可透過使用該 MapNameToOID 方法從雜湊名稱推導出。
由於 SHA-1 與 MD5 有碰撞問題,Microsoft 建議採用基於 SHA-256 或更完善的安全模型。
另請參閱
適用於
VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding)
透過使用指定的雜湊演算法與填充來確定簽名中的雜湊值,並與所提供的雜湊值比較,驗證數位簽章的有效性。
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
參數
- hash
- Byte[]
簽名資料的雜湊值。
- signature
- Byte[]
簽名資料待驗證。
- hashAlgorithm
- HashAlgorithmName
用來建立雜湊值的雜湊演算法名稱。
- padding
- RSASignaturePadding
填充物。
傳回
true如果簽名有效;否則,。 false
例外狀況
hashAlgorithm 是 null 或 Empty。
padding 不等 Pkcs1於 。