Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用Minio server解密AWS SDK加密的文件_C#_Encryption_Amazon S3_Aws Sdk_Minio - Fatal编程技术网

C# 无法使用Minio server解密AWS SDK加密的文件

C# 无法使用Minio server解密AWS SDK加密的文件,c#,encryption,amazon-s3,aws-sdk,minio,C#,Encryption,Amazon S3,Aws Sdk,Minio,我使用: 用于存储文件的minio服务器 nginx作为反向代理,能够在minio服务器上使用https .NET AWSSDK.S3通过nginx与Minio服务器通信 由于服务器端加密不适用于minio server,因此我尝试将客户端加密帮助用于AWS。但文件的解密不适用于minio服务器 当我对AWS服务器帐户使用相同的代码时,加密/解密工作得很好 在minio服务器中创建文件时,它似乎丢失了元数据 当我尝试获取文件时,出现了一个异常: AWSSDK.Core.dll中发生类型为“A

我使用:

  • 用于存储文件的minio服务器
  • nginx作为反向代理,能够在minio服务器上使用https
  • .NET AWSSDK.S3通过nginx与Minio服务器通信
由于服务器端加密不适用于minio server,因此我尝试将客户端加密帮助用于AWS。但文件的解密不适用于minio服务器

当我对AWS服务器帐户使用相同的代码时,加密/解密工作得很好

在minio服务器中创建文件时,它似乎丢失了元数据

当我尝试获取文件时,出现了一个异常:

AWSSDK.Core.dll中发生类型为“Amazon.Runtime.AmazonServiceException”的未处理异常 其他信息:无法解密对象文件-stream-27e52c5f-05d1-4296的数据-

这是我的密码

    static void Main()
    {
        string filePath = @"c:/tempPrivateKey.txt";
        string privateKey = File.ReadAllText(filePath);
        RSA rsaAlgorithm = RSA.Create();
        rsaAlgorithm.FromXmlString(privateKey);
        EncryptionMaterials encryptionMaterials = new EncryptionMaterials(rsaAlgorithm);
        var credentials = new BasicAWSCredentials(AccessKey, SecretKey);

        AmazonS3CryptoConfiguration cryptoConfig = new AmazonS3CryptoConfiguration
        {
            RegionEndpoint = RegionEndpoint.EUWest1,
            StorageMode = CryptoStorageMode.ObjectMetadata,
            ServiceURL = EndPointNginx,
            UseHttp = false,
            ForcePathStyle = true
        };

        _amazonS3Client = new AmazonS3EncryptionClient(credentials, cryptoConfig, encryptionMaterials);

        string bucketName = "bucket-" + Guid.NewGuid();

        string fileStreamKey = "file-stream-" + Guid.NewGuid();

        Stream fileStream = CreateRandomFileOnStream();

        CreateBucket(bucketName);

        AddFileToBucket(fileStreamKey, fileStream, bucketName);

        Stream fileStreamToRead = GetFile(fileStreamKey, bucketName);

        using (var reader = new StreamReader(fileStreamToRead))
        {
            Console.Out.WriteLine(reader.ReadToEnd());
        }

        DeleteFile(fileStreamKey, bucketName);

        DeleteBucket(bucketName);

        Console.ReadKey();
    }

    private static void AddFileToBucket(string fileKey, Stream fileStream, string bucketName)
    {
        Console.Out.WriteLine();
        Console.Out.WriteLine($"adding file {fileKey} to bucket {bucketName}.");

        var objectToPut = new PutObjectRequest
        {
            BucketName = bucketName,
            Key = fileKey,
            InputStream = fileStream
        };

        _amazonS3Client.PutObject(objectToPut);

        if (fileStream.CanRead)
            fileStream.Dispose();
        Console.Out.WriteLine("file added");
    }

    private static Stream GetFile(string fileKey, string bucketName)
    {
        // This line throw an exception.
        GetObjectResponse response = _amazonS3Client.GetObject(new GetObjectRequest { BucketName = bucketName, Key = fileKey });
        return response.ResponseStream;
    }

最坏情况下,我将手动加密/解密文件,但我想确定是否有解决此问题的方法。

这不应该发生您最近测试了我们的Minio服务器我们现在确实支持SSE-C。这不应该发生您最近测试了我们的Minio服务器我们现在确实支持SSE-C。