Share via


CryptographicEngine.Decrypt(CryptographicKey, IBuffer, IBuffer) Método

Definição

Descriptografa o conteúdo que foi criptografado anteriormente usando um algoritmo simétrico ou assimétrico.

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

Parâmetros

key
CryptographicKey

Chave criptográfica a ser usada para descriptografia. Isso pode ser uma chave assimétrica ou simétrica. Para obter mais informações, consulte AsymmetricKeyAlgorithmProvider e SymmetricKeyAlgorithmProvider.

data
IBuffer

Buffer que contém os dados criptografados.

iv
IBuffer

Buffer que contém o vetor de inicialização. Se um iv (vetor de inicialização) foi usado para criptografar os dados, você deve usar o mesmo IV para descriptografar os dados. Para obter mais informações, consulte Criptografar.

Retornos

Dados descriptografados.

Exemplos

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);
}

Comentários

O parâmetro de chave pode ser uma chave persistente obtida de um certificado usando a classe PersistedKeyProvider .

Se a chave for uma chave persistente e a operação de descriptografar exigir interface do usuário ou demorar muito, use o método DecryptAsync . Por exemplo, a interface do usuário é necessária ao descriptografar usando uma chave fortemente protegida. No caso em que uma chave persistente é usada e a interface do usuário é esperada, use o método DecryptAsync , pois o método Decrypt falhará.

Aplica-se a

Confira também