Share via


CryptographicEngine.DecryptAndAuthenticate Método

Definição

Descriptografa e autentica dados. Para obter mais informações e um exemplo de código completo, consulte EncryptedAndAuthenticatedData.

public:
 static IBuffer ^ DecryptAndAuthenticate(CryptographicKey ^ key, IBuffer ^ data, IBuffer ^ nonce, IBuffer ^ authenticationTag, IBuffer ^ authenticatedData);
 static IBuffer DecryptAndAuthenticate(CryptographicKey const& key, IBuffer const& data, IBuffer const& nonce, IBuffer const& authenticationTag, IBuffer const& authenticatedData);
public static IBuffer DecryptAndAuthenticate(CryptographicKey key, IBuffer data, IBuffer nonce, IBuffer authenticationTag, IBuffer authenticatedData);
function decryptAndAuthenticate(key, data, nonce, authenticationTag, authenticatedData)
Public Shared Function DecryptAndAuthenticate (key As CryptographicKey, data As IBuffer, nonce As IBuffer, authenticationTag As IBuffer, authenticatedData As IBuffer) As IBuffer

Parâmetros

key
CryptographicKey

Chave simétrica a ser usada.

data
IBuffer

Dados a serem descriptografados e autenticados.

nonce
IBuffer

Nonce a ser usado. Esse deve ser o mesmo nó usado pelo método EncryptAndAuthenticate .

authenticationTag
IBuffer

Marca de autenticação.

authenticatedData
IBuffer

Dados autenticados. Isso pode ser Null.

Retornos

Um buffer que contém os dados descriptografados. Se o método falhar, a autenticação falhará; se o método for bem-sucedido, a autenticação também terá êxito.

Exemplos

public void AuthenticatedDecryption(
    String strAlgName,
    CryptographicKey key,
    EncryptedAndAuthenticatedData objEncrypted,
    BinaryStringEncoding encoding,
    IBuffer buffNonce)
{
    // Declare a buffer to contain the decrypted data.
    IBuffer buffDecrypted;

    // Open a SymmetricKeyAlgorithmProvider object for the specified algorithm.
    SymmetricKeyAlgorithmProvider objAlgProv = SymmetricKeyAlgorithmProvider.OpenAlgorithm(strAlgName);

    // The input key must be securely shared between the sender of the encrypted message
    // and the recipient. The nonce must also be shared but does not need to be shared
    // in a secure manner. If the sender encodes the message string to a buffer, the
    // binary encoding method must also be shared with the recipient.
    // The recipient uses the DecryptAndAuthenticate() method as follows to decrypt the 
    // message, authenticate it, and verify that it has not been altered in transit.
    buffDecrypted = CryptographicEngine.DecryptAndAuthenticate(
        key,
        objEncrypted.EncryptedData,
        buffNonce,
        objEncrypted.AuthenticationTag,
        null);

    // 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

A criptografia autenticada criptografa e autentica o conteúdo em uma operação. Um autenticador, também chamado de marca, é usado durante a criptografia e a saída do processo contém um par de textos de codificação de marca. Para obter mais informações, consulte as propriedades AuthenticationTag e EncryptedData . O processo de descriptografia verifica o texto cifrado em relação à marca.

Você pode usar um algoritmo de criptografia autenticado depois de chamar o método OpenAlgorithm na classe SymmetricKeyAlgorithmProvider e especificar o nome do algoritmo a ser aberto. Os seguintes nomes de algoritmo têm suporte para criptografia autenticada e descriptografia:

Aplica-se a

Confira também