码迷,mamicode.com
首页 > Windows程序 > 详细

C#调用GPG命令进行加密解密文件操作

时间:2017-07-21 15:38:41      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:调用   use   decrypt   password   creat   inf   cut   result   csdn   

public void GPG()
{
string password = "1234567890";

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;

psi.WorkingDirectory = @"D:\sofe\GnuPG";
System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);

//解密
string sCommandLine = @"gpg --passphrase 1234567890 --output C:\Users\LWP\Desktop\cc.txt --decrypt C:\Users\LWP\Desktop\cc.txt.gpg";

//加密
//string sCommandLine = @"gpg -r liwenping -e C:\Users\LWP\Desktop\cc.txt";

process.StandardInput.WriteLine(sCommandLine);

process.StandardInput.Flush();
process.StandardInput.Close();

process.WaitForExit();

string result = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.Close();
process.Dispose();
}

//使用前先安装好GPG

//注 本人密钥和私钥尚未上传过,请另行注册

//参考  http://blog.csdn.net/puppylpg/article/details/50901779

C#调用GPG命令进行加密解密文件操作

标签:调用   use   decrypt   password   creat   inf   cut   result   csdn   

原文地址:http://www.cnblogs.com/liwp/p/7217306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!