KMS使用Boto3加密文件数据

时间:2019-05-14 19:21:01

标签: java python boto3 aws-kms

我正在使用以下代码对文件中的数据进行KMS加密。有没有办法在python中使用boto3做类似的事情?

public KmsMasterKeyProvider getkmsKeyProvider(String arn) throws IOException{
    KmsMasterKeyProvider prov =  new KmsMasterKeyProvider(
            new DefaultAWSCredentialsProviderChain(),
            Region.getRegion(getRegion()),
            createConfiguration(),
            arn);
    return prov;

}

要加密的代码

        AwsCrypto crypto = new AwsCrypto();
        KmsMasterKeyProvider prov =  util.getkmsKeyProvider(keyArn);

            FileInputStream decryptedStream = new FileInputStream(temp_data_file);
        String output = prop.getProperty(OUTPUT_TMP_PATH)+"file.out";

        final FileOutputStream out = new FileOutputStream(output);
        final CryptoOutputStream<?> encryptingStream = crypto.createEncryptingStream(prov,out);
        IOUtils.copy(decryptedStream, encryptingStream);
        encryptingStream.close();
        decryptedStream.close();

        File outputFile = new File(output);

1 个答案:

答案 0 :(得分:1)

您显示的代码示例使用的是AWS Encryption SDK [1],可用于Python [2],是的!

与您在问题中显示的内容相同的摘要是:

c = ['NA', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', 'NA']

您可以在此处[3]和我们的文档[1] [2]中找到更多示例。

[1] https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/introduction.html

[2] https://aws-encryption-sdk-python.readthedocs.io/en/latest/

[3] https://github.com/aws/aws-encryption-sdk-python/tree/master/examples/src