从亚马逊S3下载加密文件时出现问题 [英] Problem while downloading encrypted file from amazon S3

查看:202
本文介绍了从亚马逊S3下载加密文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从亚马逊下载加密文件,但是我发现错误



System.Security.Cryptography.CryptographicException被抓住了

HResult = -2146233296

消息=解密一个值需要在算法对象上设置一个键。



我尝试过的:



iam trying to download encrypted file from amazon but iam geting the error

System.Security.Cryptography.CryptographicException was caught
HResult=-2146233296
Message=Decrypting a value requires that a key be set on the algorithm object.

What I have tried:

cloudEncryptS3 = new cAmazonS3();
                        cloudEncryptS3.cAmazonEncryptS3(cloudAccountObj.AccountId, cloudAccountObj.SecretKey, cloudAccountObj.IsSSL == Constants.CONSTANT_ONE ? true : false, item.EncryptAlgoName, item.EncryptAlgoValue);

			request = new GetObjectRequest
                        {
                            BucketName = bucketName,
                            Key = keyName
                        };
                        

                        try
                        {
                            response = encryptClient.GetObject(request);
                        }
                        catch (Exception ex)
                        {
                            cGlobalSettings.oLogger.WriteLogException("| S3Progress.cs::DownLoadS3File() |", ex);



    public void cAmazonEncryptS3(string accessKey, string secretKey, bool IsSSL, string algoName, int algoValue)
        {
            encryptClient = null;
            AmazonS3CryptoConfiguration config = null;
            EncryptionMaterials encryp = null;
            Aes aesObj = null;
            DES desObj = null;
            TripleDES desTripleObj = null;
            RC2 rcObj = null;
            try
            {
                config = new AmazonS3CryptoConfiguration
                {
                    ServiceURL = "https://s3.amazonaws.com",
                    UseHttp = IsSSL,
                    StorageMode = CryptoStorageMode.ObjectMetadata
                };
                if (algoName.ToLower().Contains("aes"))
                {

                    aesObj = Aes.Create();
                    aesObj.BlockSize = algoValue;
                    encryp = new EncryptionMaterials(aesObj);
                }
                else if (algoName.ToLower().Contains("des"))
                {
                    if (algoValue == 64)
                    {
                        desObj = DES.Create();
                        desObj.BlockSize = algoValue;
                        encryp = new EncryptionMaterials(desObj);
                    }
                    else
                    {
                        desTripleObj = TripleDES.Create();
                        desTripleObj.BlockSize = algoValue;
                        encryp = new EncryptionMaterials(desTripleObj);
                    }
                }
                else if (algoName.ToLower().Contains("rc"))
                {
                    rcObj = RC2.Create();
                    rcObj.BlockSize = algoValue;
                    encryp = new EncryptionMaterials(rcObj);
                }
                else
                {
                    aesObj = Aes.Create();
                    aesObj.BlockSize = 128;
                    encryp = new EncryptionMaterials(aesObj);
                }

                encryptClient = new AmazonS3EncryptionClient(accessKey, secretKey, config, encryp);
            }
            catch (Exception ex)
            {
                cGlobalSettings.oLogger.WriteLogException("cAmazonS3.cs::cAmazonEncryptS3()", ex);
            }
            finally
            {
                config = null;
                encryp = null;
                aesObj = null;
                desObj = null;
                desTripleObj = null;
                rcObj = null;
            }
        }                    }

推荐答案

消息很明确!

Message is pretty explicit!
引用:

System.Security.Cryptography.CryptographicException被捕获

HResult = -2146233296

消息=解密一个值需要在算法对象上设置一个键。

System.Security.Cryptography.CryptographicException was caught
HResult=-2146233296
Message=Decrypting a value requires that a key be set on the algorithm object.

这里你不明白的是什么?



What you don't understand here ?

Decrypting a value requires that a key be set on the algorithm object



告诉您需要提供解密密钥。



你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。


Tells you that you need to provide a decryption key.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.


最后我找到了t他解决了我的问题



客户端数据加密 - AWS开发人员博客 - Windows和.NET [ ^ ]
finally i found the solution of my problem

Client Side Data Encryption with AWS SDK for .NET and Amazon S3 - AWS Developer Blog - Windows and .NET[^]


这篇关于从亚马逊S3下载加密文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆