Condividi tramite


CryptographicEngine.Decrypt(CryptographicKey, IBuffer, IBuffer) Metodo

Definizione

Decrittografa il contenuto crittografato in precedenza usando un algoritmo simmetrico o asimmetrico.

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

Parametri

key
CryptographicKey

Chiave crittografica da usare per la decrittografia. Può trattarsi di una chiave asimmetrica o simmetrica. Per altre informazioni, vedere AsymmetricKeyAlgorithmProvider e SymmetricKeyAlgorithmProvider.

data
IBuffer

Buffer contenente i dati crittografati.

iv
IBuffer

Buffer contenente il vettore di inizializzazione. Se è stato usato un vettore di inizializzazione (IV) per crittografare i dati, è necessario usare lo stesso IV per decrittografare i dati. Per altre informazioni, vedere Encrypt.

Restituisce

Dati decrittografati.

Esempio

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

Commenti

Il parametro chiave può essere una chiave persistente ottenuta da un certificato usando la classe PersistedKeyProvider .

Se la chiave è una chiave persistente e l'operazione di decrittografia richiede un'interfaccia utente o richiede molto tempo, usare invece il metodo DecryptAsync . Ad esempio, l'interfaccia utente è necessaria quando si decrittografa usando una chiave protetta in modo sicuro. Nel caso in cui venga usata una chiave persistente e l'interfaccia utente sia prevista, usare il metodo DecryptAsync perché il metodo Decrypt avrà esito negativo.

Si applica a

Vedi anche