如何使用OpenPGP将一个BLOB解密为另一个BLOB [英] How to use OpenPGP to decrypt from one blob to another

查看:124
本文介绍了如何使用OpenPGP将一个BLOB解密为另一个BLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我已经知道我必须在ADF中创建自定义批处理活动才能做到这一点,我只是想不出如何将BLOB发送到OpenPGP

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

using (FileStream inputFileStream = new FileStream(@"C:TEMPkeyscontent__encrypted2.pgp", FileMode.Open))
using (Stream outputFileStream = File.Create(@"C:TEMPkeyscontent__decrypted2.txt"))
using (Stream privateKeyStream = new FileStream(@"C:TEMPkeysprivate.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");

推荐答案

我发现自己做错了什么。在传递到DecyptStream之前,我没有将流位置重置为零。此代码起作用:

        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);

这篇关于如何使用OpenPGP将一个BLOB解密为另一个BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆