简体   繁体   English

C#将文本/数据流传输到zip / gpg,而不是传递应用程序文件名?

[英]C# Stream text/data to zip/gpg instead of passing app a filename?

I currently have an app written in C# that can take a file and encrypt it using gpg.exe 我目前有一个用C#编写的应用程序,可以获取文件并使用gpg.exe对其进行加密

What I'm trying to do is, instead of 1. Creating a file (from database queries usually) 2. encrypting the file 3. deleting the non-encrypted file 我想做的是,而不是1.创建文件(通常是从数据库查询中)2.加密文件3.删除未加密的文件

I want to 我想要

  1. Gather info into memory (into a dictionary or a list or whatever) 将信息收集到内存中(放入字典,列表或其他内容)
  2. stream the text/data into gpg.exe to end up with the encrypted file outputted 将文本/数据流式传输到gpg.exe,最终输出加密文件

I've looked into pipestream, redirecting standard input to the gpg process, etc, but I haven't figured out a way to trick gpg.exe into accepting streamed text/data instead of a file on the hard drive. 我研究了管道流,将标准输入重定向到gpg进程等,但是我还没有找到一种方法来欺骗gpg.exe接受流文本/数据而不是硬盘上的文件。

Initially figured if I could do it for gpg, I could also do it for Zip as well, but I'm wondering if it's even possible. 最初想出是否可以为gpg做,我也可以为Zip做,但是我想知道是否有可能。 Found some refs to popen which seems to be php related, but nothing for c#. 找到了一些似乎与php相关的popen引用,但对于C#没有任何帮助。

Essentially, I'm looking to do the below programatically with text.txt being stuff in memory streamed to the app instead of an actual file on the hard drive. 本质上,我希望通过编程方式执行以下操作,其中text.txt是流传输到应用程序的内存中的内容,而不是硬盘驱动器上的实际文件。

C:\\Program Files\\GNU\\GnuPG>type C:\\test.txt | C:\\ Program Files \\ GNU \\ GnuPG>键入C:\\ test.txt | zip > plubber.zip C:\\Program Files\\GNU\\GnuPG>type C:\\test.txt | zip> plubber.zip C:\\ Program Files \\ GNU \\ GnuPG>键入C:\\ test.txt | gpg -er "mycomp_operations " > Test.pgp gpg -er“ mycomp_operations”> Test.pgp

Thanks for any help you may be able to give :) 感谢您的帮助,您可以:)

Tony! 托尼!

Benton Stark has written a good wrapper for GnuPG which demonstrates (among other things) how to take data from a Stream, pipe it into the GPG executable and write the output back to a stream - all in C#. Benton Stark已经为GnuPG编写了一个很好的包装器,其中展示了如何从Stream中获取数据,将其通过管道传输到GPG可执行文件中以及如何将输出写回到流中(全部使用C#)。

Benton has answered another question with a link to his website. 本顿用他的网站的链接回答了另一个问题 Benton writes: 本顿写道:

You can try using my open source and free GnuPG wrapper for C# (and VB.NET). 您可以尝试使用针对C#(和VB.NET)的开放源代码和免费的GnuPG包装器。 All the code is licensed via MIT, non-GPL restrictions. 所有代码均通过MIT(非GPL限制)许可。 You can find the release with source code on Sourceforge.net. 您可以在Sourceforge.net上找到包含源代码的发行版。

http://sourceforge.net/projects/starksoftopenpg/ http://sourceforge.net/projects/starksoftopenpg/

You can use DotNetZip to create a zip file in-memory, but I don't know how that would interface with the gpg stuff. 您可以使用DotNetZip在内存中创建一个zip文件,但是我不知道该如何与gpg东西交互。 DotNetZip can do AES encryption, but that is obviously a different model from PGP or GPG. DotNetZip可以进行AES加密,但这显然不同于PGP或GPG。

Just a quick googly search turned up 只需快速搜索即可
this hint on GPG. 关于GPG的提示

Looks like they run the gpg.exe in a separate process, sitting there waiting for input. 看起来他们是在一个单独的进程中运行gpg.exe,坐在那里等待输入。

Please review the BouncyCastle C# implementation at: 请在以下位置查看BouncyCastle C#的实现:

http://www.bouncycastle.org/csharp/ http://www.bouncycastle.org/csharp/

This will allow GPG inprocess encryption and decryption without external files. 这将允许GPG进行进程内加密和解密,而无需外部文件。 I am currently using it to do the same thing for a BizTalk pipeline component. 我目前正在使用它对BizTalk管道组件执行相同的操作。

Using our SecureBlackbox components you can avoid calling external program for ZIP or PGP operations. 使用我们的SecureBlackbox组件,您可以避免为ZIP或PGP操作调用外部程序。 The components operate with streams and don't need temporary files. 这些组件与流一起运行,不需要临时文件。

好吧,命名管道完成了您正在讨论的大部分内容,但是老实说这是不值得的……在大多数情况下,使用临时文件是一种合理的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM