Share via


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

Definición

Descifra el contenido que se cifró anteriormente mediante un algoritmo simétrico o asimé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

Clave criptográfica que se va a usar para el descifrado. Puede ser una clave asimétrica o simétrica. Para obtener más información, vea AsymmetricKeyAlgorithmProvider y SymmetricKeyAlgorithmProvider.

data
IBuffer

Búfer que contiene los datos cifrados.

iv
IBuffer

Búfer que contiene el vector de inicialización. Si se usó un vector de inicialización (IV) para cifrar los datos, debe usar el mismo IV para descifrar los datos. Para obtener más información, vea Cifrar.

Devoluciones

Datos descifrados.

Ejemplos

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

Comentarios

El parámetro key puede ser una clave persistente obtenida de un certificado mediante la clase PersistedKeyProvider .

Si la clave es una clave persistente y la operación de descifrado requiere interfaz de usuario o tarda mucho tiempo, use el método DecryptAsync en su lugar. Por ejemplo, la interfaz de usuario es necesaria al descifrar mediante una clave fuertemente protegida. En caso de que se use una clave persistente y se espera la interfaz de usuario, use el método DecryptAsync , ya que se producirá un error en el método Decrypt.

Se aplica a

Consulte también