CryptographicEngine.Decrypt(CryptographicKey, IBuffer, IBuffer) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用對稱或非對稱演算法解密先前加密的內容。
public:
static IBuffer ^ Decrypt(CryptographicKey ^ key, IBuffer ^ data, IBuffer ^ iv);
static IBuffer Decrypt(CryptographicKey const& key, IBuffer const& data, IBuffer const& iv);
public static IBuffer Decrypt(CryptographicKey key, IBuffer data, IBuffer iv);
function decrypt(key, data, iv)
Public Shared Function Decrypt (key As CryptographicKey, data As IBuffer, iv As IBuffer) As IBuffer
參數
- key
- CryptographicKey
用於解密的密碼編譯金鑰。 這可以是非對稱或對稱金鑰。 如需詳細資訊,請參閱 AsymmetricKeyAlgorithmProvider 和 SymmetricKeyAlgorithmProvider。
- data
- IBuffer
包含加密資料的緩衝區。
傳回
解密的資料。
範例
public void SampleCipherDecryption(
String strAlgName,
IBuffer buffEncrypt,
IBuffer iv,
BinaryStringEncoding encoding,
CryptographicKey key)
{
// Declare a buffer to contain the decrypted data.
IBuffer buffDecrypted;
// Open an symmetric algorithm provider for the specified algorithm.
SymmetricKeyAlgorithmProvider objAlg = SymmetricKeyAlgorithmProvider.OpenAlgorithm(strAlgName);
// The input key must be securely shared between the sender of the encrypted message
// and the recipient. The initialization vector must also be shared but does not
// need to be shared in a secure manner. If the sender encodes a message string
// to a buffer, the binary encoding method must also be shared with the recipient.
buffDecrypted = CryptographicEngine.Decrypt(key, buffEncrypt, iv);
// Convert the decrypted buffer to a string (for display). If the sender created the
// original message buffer from a string, the sender must tell the recipient what
// BinaryStringEncoding value was used. Here, BinaryStringEncoding.Utf8 is used to
// convert the message to a buffer before encryption and to convert the decrypted
// buffer back to the original plaintext.
String strDecrypted = CryptographicBuffer.ConvertBinaryToString(encoding, buffDecrypted);
}
備註
key參數可以是使用PersistedKeyProvider類別從憑證取得的保存金鑰。
如果金鑰是保存的金鑰,而且解密作業需要 UI 或花費很長的時間,請改用 DecryptAsync 方法。 例如,使用強式保護的金鑰解密時,需要 UI。 在使用保存金鑰且預期 UI 的情況下,請使用 DecryptAsync 方法,因為 Decrypt 方法將會失敗。