How to use OpenPGP to decrypt from one blob to another(如何使用OpenPGP将一个BLOB解密为另一个BLOB)
本文介绍了如何使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
编程基础网
本文标题为:如何使用OpenPGP将一个BLOB解密为另一个BLOB
基础教程推荐
猜你喜欢
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
