简体   繁体   中英

How to decrypt AWS S3 file during download?

Here is my download code :

 IAmazonS3 client;

            string key = tenant_id + @"/files/" + filename;
            try
            {
                using (client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1))
                {
                    GetObjectRequest request = new GetObjectRequest
                    {
                        BucketName = existingBucketName,
                        Key = key
                    };

                    using (GetObjectResponse response = client.GetObject(request))
                    {
                        string dest = path;
                        if (!File.Exists(dest))
                        {
                            response.WriteResponseStreamToFile(dest);
                        }
                    }
                }
                return true;
            }

I would like to decrypt files during the download process. I've gone through the support docs but unable to proceed. What changes do I need to make in my current code to achieve this ?

It depends on how the file was encrypted. S3 supports client-side encryption and server-side encryption .

If the file is encrypted using server-side encryption, either S3 is managing the keys or you need to provide the key in your request. If the file was encrypted client-side prior to being uploaded to S3 then you must decrypt the downloaded file yourself. In this case check out the AmazonS3EncryptionClient to help make things easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM