次の方法で共有


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。 これは、 EncryptAndAuthenticate メソッドで使用されるのと同じ nonce である必要があります。

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

}

注釈

認証された暗号化は、1 回の操作でコンテンツを暗号化して認証します。 認証子 (タグとも呼ばれます) は暗号化中に使用され、プロセスの出力にはタグと暗号テキストのペアが含まれています。 詳細については、 AuthenticationTag プロパティと EncryptedData プロパティに関するページを 参照してください。 復号化プロセスでは、タグに対して暗号テキストが検証されます。

認証された暗号化アルゴリズムは、SymmetricKeyAlgorithmProvider クラスで OpenAlgorithm メソッドを呼び出し、開くアルゴリズムの名前を指定した後で使用できます。 認証された暗号化と暗号化解除では、次のアルゴリズム名がサポートされています。

適用対象

こちらもご覧ください