Partager via


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

Définition

Déchiffre le contenu précédemment chiffré à l’aide d’un algorithme symétrique ou asymétrique.

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

Paramètres

key
CryptographicKey

Clé de chiffrement à utiliser pour le déchiffrement. Il peut s’agir d’une clé asymétrique ou symétrique. Pour plus d’informations, consultez AsymmetricKeyAlgorithmProvider et SymmetricKeyAlgorithmProvider.

data
IBuffer

Mémoire tampon qui contient les données chiffrées.

iv
IBuffer

Mémoire tampon qui contient le vecteur d’initialisation. Si un vecteur d’initialisation (IV) a été utilisé pour chiffrer les données, vous devez utiliser le même vecteur d’initialisation pour déchiffrer les données. Pour plus d’informations, consultez Chiffrer.

Retours

Données déchiffrées.

Exemples

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

Remarques

Le paramètre key peut être une clé persistante obtenue à partir d’un certificat à l’aide de la classe PersistedKeyProvider .

Si la clé est une clé persistante et que l’opération de déchiffrement nécessite une interface utilisateur ou prend beaucoup de temps, utilisez plutôt la méthode DecryptAsync . Par exemple, l’interface utilisateur est requise lors du déchiffrement à l’aide d’une clé fortement protégée. Dans le cas où une clé persistante est utilisée et que l’interface utilisateur est attendue, utilisez la méthode DecryptAsync , car la méthode Decrypt échoue.

S’applique à

Voir aussi