在Azure Blob上对大文件进行PGP加密

问题描述

我正在使用PGPCore加密/解密Azure函数中的文件文件存储在Blob块容器中。 加密可以正常工作,更不用说了。

解密反而使我有些头疼。

理想情况下,我想在BlobBlockClient上使用OpenWrite/Read方法,以避免在内存中下载和加密。我希望使用这样的东西:

await using var sourceStream = await sourceBlobClient.OpenReadAsync();

var destBlobClient = destContainer.GetBlockBlobClient(command.sourcePath);
await using var destStream = await destBlobClient.OpenWriteAsync(true);

await using var privateKey = _pgpKeysProvider.GetPrivate();
using var pgp = new PgpCore.PGP();

await pgp.DecryptStreamAsync(sourceStream,destStream,privateKey.Key,privateKey.Passphrase);

但是我遇到一些问题:

  1. OpenReadAsync()返回不可搜索的流,显然DecryptStreamAsync()无法使用它。为了减轻这种情况,我正在下载内存中的Blob,我确实希望避免:
    await using var sourceStream = new MemoryStream();
    await sourceBlobClient.DownloadToAsync(sourceStream);
    sourceStream.Position = 0;
    
    有什么办法可以解决这个问题?
  2. 即使我咬着子弹并将加密的文件下载到MemoryStream中,DecryptStreamAsync()仍返回空流。到目前为止,我发现的唯一解决方案是解密到另一个MemoryStream ,然后将其上传到Blob容器。我也想避免。我什至试图摆脱using并在流上手动调用dispose(),以防万一那里有任何潜在的问题。没有运气。

文件不是问题,我担心大文件(例如4GB或更大)

有什么建议吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)