CryptographicEngine.VerifySignature 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
驗證訊息簽章。
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、雜湊和簽章。