다음을 통해 공유


CryptographicEngine.EncryptAndAuthenticate 메서드

정의

인증된 암호화를 수행합니다.

public:
 static EncryptedAndAuthenticatedData ^ EncryptAndAuthenticate(CryptographicKey ^ key, IBuffer ^ data, IBuffer ^ nonce, IBuffer ^ authenticatedData);
 static EncryptedAndAuthenticatedData EncryptAndAuthenticate(CryptographicKey const& key, IBuffer const& data, IBuffer const& nonce, IBuffer const& authenticatedData);
public static EncryptedAndAuthenticatedData EncryptAndAuthenticate(CryptographicKey key, IBuffer data, IBuffer nonce, IBuffer authenticatedData);
function encryptAndAuthenticate(key, data, nonce, authenticatedData)
Public Shared Function EncryptAndAuthenticate (key As CryptographicKey, data As IBuffer, nonce As IBuffer, authenticatedData As IBuffer) As EncryptedAndAuthenticatedData

매개 변수

key
CryptographicKey

암호화에 사용할 대칭 키입니다.

data
IBuffer

암호화 및 인증할 데이터입니다.

nonce
IBuffer

사용할 Nonce입니다. nonce는 반복 가능성이 최소인 변수입니다. 예를 들어 각 용도에 대해 새로 생성된 임의 값, 타임스탬프를 사용하거나 시퀀스 번호 또는 이러한 값을 조합하여 사용할 수 있습니다. Microsoft GCM 구현에는 12바이트 nonce가 필요합니다. CCM 구현에는 7-13바이트 nonce가 필요합니다.

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

}

설명

인증된 암호화는 한 작업에서 콘텐츠를 암호화하고 인증합니다. 태그라고도 하는 인증자는 암호화 중에 사용되며 프로세스의 출력에는 태그-암호 텍스트 쌍이 포함됩니다. 자세한 내용은 AuthenticationTagEncryptedData 속성을 참조하세요. 암호 해독 프로세스는 태그에 대해 암호 텍스트를 확인합니다.

SymmetricKeyAlgorithmProvider 클래스에서 OpenAlgorithm 메서드를 호출하고 열 알고리즘의 이름을 지정한 후 인증된 암호화 알고리즘을 사용할 수 있습니다. 인증된 암호화 및 암호 해독에는 다음 알고리즘 이름이 지원됩니다.

적용 대상

추가 정보