如何以加密形式上传文件

发布于 2024-12-11 02:57:53 字数 709 浏览 0 评论 0原文

我正在开发一个将文件上传到亚马逊的应用程序。亚马逊提供 一种方法 WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256) 来加密文件,但它不起作用。它将文本保存为纯文本。

public static void UploadFile()
{
    new Program();
    var key = "a";
    //key = ReplaceDblSlashToSingleFwdSlash(key);
    //path = ReplaceFwdSlashToBackSlash(path);
    var request = new PutObjectRequest();
    request.WithBucketName("demo")
           .WithContentBody("i am achal kumar")
           .WithKey(key)
           .WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256);
    //request.PutObjectProgressEvent += displayFileProgress;
    S3Response response = s3Client.PutObject(request);
    response.Dispose();
}

I am developing an application that will upload files to Amazon. Amazon provides
a method WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256) to encrypt files but it is not working. It is saving text as a plain text.

public static void UploadFile()
{
    new Program();
    var key = "a";
    //key = ReplaceDblSlashToSingleFwdSlash(key);
    //path = ReplaceFwdSlashToBackSlash(path);
    var request = new PutObjectRequest();
    request.WithBucketName("demo")
           .WithContentBody("i am achal kumar")
           .WithKey(key)
           .WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256);
    //request.PutObjectProgressEvent += displayFileProgress;
    S3Response response = s3Client.PutObject(request);
    response.Dispose();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眼睛不忧郁 2024-12-18 02:57:53

您的数据可能已加密,并且只是使用您正在测试的数据自动解密。

http://aws.typepad.com /aws/2011/10/new-amazon-s3-server-side-encryption.html

您无需付出任何努力即可解密加密数据。什么时候
你得到一个加密的对象,我们获取并解密密钥,然后
用它来解密您的数据。我们还在
对 GET 的响应让您知道数据存储在
Amazon S3 中的加密形式。

Your data is likely encrypted and just being automatically decrypted with your get that you are testing with.

http://aws.typepad.com/aws/2011/10/new-amazon-s3-server-side-encryption.html

Decryption of the encrypted data requires no effort on your part. When
you GET an encrypted object, we fetch and decrypt the key, and then
use it to decrypt your data. We also include an extra header in the
response to the GET to let you know that the data was stored in
encrypted form in Amazon S3.

莫相离 2024-12-18 02:57:53

您可以使用以下代码来检查是否已加密..因为aws s3在将对象返回给您时已经解密了该对象。

因此,请尝试以下代码来检查对象是否在 amazon s3 上加密,

GetObjectMetadataRequest meta = new GetObjectMetadataRequest();

GetObjectMetadataResponse response = s3Client.GetObjectMetadata(meta);
if(response.ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256)
{
   // your code goes here
}

我希望这可以有所帮助

you can use the following code to check if the is encrypted or not .. because aws s3 they already decrypt the object when they return it to you.

so try the following code to check if the object is encrypted on amazon s3

GetObjectMetadataRequest meta = new GetObjectMetadataRequest();

GetObjectMetadataResponse response = s3Client.GetObjectMetadata(meta);
if(response.ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256)
{
   // your code goes here
}

i hope this could help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文