

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Amazon Connect에서 민감한 고객 입력 암호화
<a name="encrypt-data"></a>

흐름에서 수집한 중요한 데이터를 암호화할 수 있습니다. 이렇게 하려면 퍼블릭 키 암호화를 사용해야 합니다.

Amazon Connect를 구성할 때는 먼저 퍼블릭 키를 제공합니다. 데이터를 암호화할 때 사용되는 키입니다. 나중에 프라이빗 키를 소유하고 있음을 증명하는 서명이 포함된 X.509 인증서를 제공합니다.

데이터를 수집하는 흐름에서 X.509 인증서를 제공함으로써 **저장된 고객 입력** 시스템 속성을 사용하여 캡처된 데이터를 암호화합니다. 이 기능을 사용하려면 `.pem` 형식의 키를 업로드해야 합니다. 이 암호화 키는 흐름에서 사용할 인증서의 서명을 확인하는 데 사용됩니다.

**참고**  
교체를 원활하게 하기 위해 암호화 키를 최대 두 개까지 동시에 활성화할 수 있습니다.

**저장된 고객 입력** 속성에서 데이터를 해독하려면 AWS Encryption SDK를 사용합니다. 자세한 내용은 [AWS Encryption SDK 개발자 안내서](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/)를 참조하세요.

## Amazon Connect로 암호화된 데이터를 해독하는 방법
<a name="sample-decryption"></a>

다음 코드 샘플은 AWS Encryption SDK를 사용하여 데이터를 해독하는 방법을 보여 줍니다.

```
package com.amazonaws;
 
import com.amazonaws.encryptionsdk.AwsCrypto;
import com.amazonaws.encryptionsdk.CryptoResult;
import com.amazonaws.encryptionsdk.jce.JceMasterKey;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
 
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.Security;
import java.security.interfaces.RSAPrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
 
public class AmazonConnectDecryptionSample {
 
    // The Provider 'AmazonConnect' is used during encryption, this must be used during decryption for key
    // to be found
    private static final String PROVIDER = "AmazonConnect";
 
    // The wrapping algorithm used during encryption
    private static final String WRAPPING_ALGORITHM = "RSA/ECB/OAEPWithSHA-512AndMGF1Padding";
 
    /**
     * This sample show how to decrypt data encrypted by Amazon Connect.
     * To use, provide the following command line arguments: [path-to-private-key] [key-id] [cyphertext]
     * Where:
     *  path-to-private-key is a file containing the PEM encoded private key to use for decryption
     *  key-id is the key-id specified during encryption in your flow
     *  cyphertext is the result of the encryption operation from Amazon Connect
     */
    public static void main(String[] args) throws IOException, GeneralSecurityException {
        String privateKeyFile = args[0]; // path to PEM encoded private key to use for decryption
        String keyId = args[1]; // this is the id used for key in your flow
        String cypherText = args[2]; // the result from flow
 
        Security.addProvider(new BouncyCastleProvider());
 
        // read the private key from file
        String privateKeyPem = new String(Files.readAllBytes(Paths.get(privateKeyFile)), Charset.forName("UTF-8"));
        RSAPrivateKey privateKey =  getPrivateKey(privateKeyPem);
 
        AwsCrypto awsCrypto = new AwsCrypto();
        JceMasterKey decMasterKey =
                JceMasterKey.getInstance(null,privateKey, PROVIDER, keyId, WRAPPING_ALGORITHM);
        CryptoResult<String, JceMasterKey> result = awsCrypto.decryptString(decMasterKey, cypherText);
 
        System.out.println("Decrypted: " + result.getResult());
    }
 
    public static RSAPrivateKey getPrivateKey(String privateKeyPem) throws IOException, GeneralSecurityException {
        String privateKeyBase64 = privateKeyPem
                .replace("-----BEGIN RSA PRIVATE KEY-----\n", "")
                .replace("-----END RSA PRIVATE KEY-----", "")
                .replaceAll("\n", "");
        byte[] decoded = Base64.getDecoder().decode(privateKeyBase64);
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decoded);
        RSAPrivateKey privKey = (RSAPrivateKey) kf.generatePrivate(keySpec);
        return privKey;
    }
}
```