CryptographicEngine.DecryptAndAuthenticate Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Расшифровывает и проверяет подлинность данных. Дополнительные сведения и полный пример кода см. в разделе 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
Параметры
- key
- CryptographicKey
Симметричный ключ для использования.
- data
- IBuffer
Данные для расшифровки и проверки подлинности.
- nonce
- IBuffer
Использование nonce. Это должен быть тот же nonce, который используется методом EncryptAndAuthenticate .
- authenticationTag
- IBuffer
Тег проверки подлинности.
- authenticatedData
- IBuffer
Данные, прошедшие проверку подлинности. Это может быть null.
Возвращаемое значение
Буфер, содержащий расшифрованные данные. Если метод завершается сбоем, проверка подлинности завершается сбоем; Если метод выполнен успешно, проверка подлинности также выполнена.
Примеры
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);
}
Комментарии
Шифрование с проверкой подлинности шифрует и проверяет подлинность содержимого в одной операции. Средство проверки подлинности, также называемое тегом, используется во время шифрования, а выходные данные процесса содержат пару тегов и шифров. Дополнительные сведения см. в разделах Свойства AuthenticationTag и EncryptedData . Процесс расшифровки проверяет зашифрованный текст по тегу .
Алгоритм шифрования, прошедший проверку подлинности, можно использовать после вызова метода OpenAlgorithm в классе SymmetricKeyAlgorithmProvider и указания имени открываемого алгоритма. Для шифрования и расшифровки с проверкой подлинности поддерживаются следующие имена алгоритмов:
- SymmetricAlgorithmNames.AesGcm
- SymmetricAlgorithmNames.AesCcm Полный пример кода, содержащий следующий пример кода, см. в разделе Класс EncryptedAndAuthenticatedData .