【问题标题】:How to use OpenPGP to decrypt from one blob to another如何使用 OpenPGP 从一个 blob 解密到另一个
【发布时间】:2019-04-06 23:31:42
【问题描述】:

我每天都会将几个 PGP 加密文件导入我的 Blob 存储区。我需要能够将它们解密到同一个 blob 容器中的另一个位置。

我已经知道我必须创建一个自定义批处理活动才能在 ADF 中执行此操作,我只是无法弄清楚如何将 blob 获取到 OpenPgp

来自 bitscry.com 的示例代码建议使用流作为示例:

using (FileStream inputFileStream = new FileStream(@"C:\TEMP\keys\content__encrypted2.pgp", FileMode.Open))
using (Stream outputFileStream = File.Create(@"C:\TEMP\keys\content__decrypted2.txt"))
using (Stream privateKeyStream = new FileStream(@"C:\TEMP\keys\private.asc", FileMode.Open))
    pgp.DecryptStream(inputFileStream, outputFileStream, privateKeyStream, "password");

我尝试将 blob 作为流打开,但它不起作用。

这是尝试将 blob 用作流的代码:

        Stream sourceStream = keyBlockBlob.OpenRead();
        Stream keyStream = sourceCloudBlockBlob.OpenRead();
        Stream targetStream = targetCloudBlockBlob.OpenWrite();

        pgp.DecryptStream(sourceStream, targetStream, keyStream, "password");

【问题讨论】:

    标签: c# azure-storage openpgp


    【解决方案1】:

    我发现我做错了什么。在传递给 DecryptStream 之前,我没有将流位置重置为零。此代码有效:

            var sourceStream = new MemoryStream();
            var keyStream = new MemoryStream();
            var targetStream = new MemoryStream();
    
            sourceCloudBlockBlob.DownloadToStream(sourceStream);
            sourceStream.Position = 0;
    
            keyBlockBlob.DownloadToStream(keyStream);
            keyStream.Position = 0;
    
    
            pgp.DecryptStream(sourceStream, targetStream, keyStream, "password");
            targetStream.Position = 0;
            targetCloudBlockBlob.UploadFromStream(targetStream);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-29
      • 2021-06-27
      • 2020-05-07
      • 2020-03-26
      • 2020-09-24
      • 1970-01-01
      • 2011-12-07
      • 1970-01-01
      相关资源
      最近更新 更多