Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
            }
        }                    }
Posted
Updated 15-Sep-16 1:33am

Message is pretty explicit!
Quote:
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

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.
 
Share this answer
 
v2
Comments
srilekhamenon 15-Sep-16 6:02am    
iam already providing accesskey and SecretKey
Patrice T 15-Sep-16 6:07am    
May be you should read the documentation ?
you are told that a key is missing!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900