gpt4 book ai didi

c# - 使用 C# 解密和解压缩 Azure Blob 存储中的数据

转载 作者:行者123 更新时间:2023-12-03 05:24:46 25 4
gpt4 key购买 nike

在上传到 Azure Blob 存储之前,我使用以下代码来加密和压缩数据

           //calling the API for Data
var response = httpclient.Send(webRequest);

//Compressing
using MemoryStream compressedMemoryStream = new MemoryStream();
using (Stream bodyStream = response.Content.ReadAsStream())
{
using (GZipStream compressionStream = new GZipStream(compressedMemoryStream,
CompressionMode.Compress, true))
{
await bodyStream.CopyToAsync(compressionStream);
}
}
compressedMemoryStream.Position = 0;

//Uploading to blob
//options includes the details about encrypting
blob.UploadFromStream(compressedMemoryStream, compressedMemoryStream.Length, null, options, null);

数据已成功上传到 Azure Blob

但是当我尝试下载 -> 解密 -> 解压缩时,它给了我空数据

下面的代码

            
var compressedStream = new MemoryStream();

//Download and decrypt Blob data to MemoryStream
dblob.DownloadToStream(compressedStream, null, doptions, null);

//Decompress Code
var bigStream = new GZipStream(compressedStream, CompressionMode.Decompress);
var bigStreamOut = new MemoryStream();
bigStream.CopyTo(bigStreamOut);
output = Encoding.UTF8.GetString(bigStreamOut.ToArray());


// “output is empty".
Console.WriteLine(output);

最佳答案

您需要将位置设置为 0。以下代码应该有效:

var compressedStream = new MemoryStream();

//Download and decrypt Blob data to MemoryStream
dblob.DownloadToStream(compressedStream, null, doptions, null);
compressedStream.Position = 0;

//Decompress Code
var bigStream = new GZipStream(compressedStream, CompressionMode.Decompress);
var bigStreamOut = new MemoryStream();
bigStream.CopyTo(bigStreamOut);
output = Encoding.UTF8.GetString(bigStreamOut.ToArray());


// “output is empty".
Console.WriteLine(output);

关于c# - 使用 C# 解密和解压缩 Azure Blob 存储中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69830293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com