CryptographicEngine.VerifySignature 方法

定义

验证消息签名。

public:
 static bool VerifySignature(CryptographicKey ^ key, IBuffer ^ data, IBuffer ^ signature);
 static bool VerifySignature(CryptographicKey const& key, IBuffer const& data, IBuffer const& signature);
public static bool VerifySignature(CryptographicKey key, IBuffer data, IBuffer signature);
function verifySignature(key, data, signature)
Public Shared Function VerifySignature (key As CryptographicKey, data As IBuffer, signature As IBuffer) As Boolean

参数

key
CryptographicKey

用于验证的密钥。 这必须与之前用于对消息进行签名的密钥相同。

data
IBuffer

要验证的消息。

signature
IBuffer

之前通过要验证的消息计算的签名。

返回

Boolean

bool

如果消息已验证,则为 true

示例

public void SampleVerifyHMAC(
    IBuffer buffMsg,
    CryptographicKey hmacKey,
    IBuffer buffHMAC)
{
    // The input key must be securely shared between the sender of the HMAC and 
    // the recipient. The recipient uses the CryptographicEngine.VerifySignature() 
    // method as follows to verify that the message has not been altered in transit.
    Boolean IsAuthenticated = CryptographicEngine.VerifySignature(hmacKey, buffMsg, buffHMAC);
    if (!IsAuthenticated)
    {
        throw new Exception("The message cannot be verified.");
    }
}

注解

为了对内容进行签名,发送方通常会在消息上创建哈希,对 (签名) 加密哈希,然后发送签名和未加密的消息。 接收方使用相同的密钥和算法来计算消息的哈希,解密签名,并将解密的签名与哈希值进行比较。 如果两者匹配,则接收者可以更加清楚地确定该消息确实来自发送者并且传输期间并未改变。 有关详细信息,请参阅 MAC、哈希和签名

适用于