加密

 // create an instance of the library
PGPLib pgp = new PGPLib(); // Import the main company public key
pgp.AddMasterKey(@"xx.asc"); // after the encryption the output file will be encrypted with two keys
pgp.EncryptFile(@"input.txt", @"xx.asc", @"input.txt.pgp");
MessageBox.Show("杀杀杀");

解密

  // initialize the library
PGPLib pgp = new PGPLib(); string inputFileLocation = @"input.txt.pgp";
string privateKeyLocation = @"pv.asc";
string privateKeyPassword = "6446-";
string decryptedOutput = @"input2.txt"; try
{
string originalFileName =
pgp.DecryptFile(inputFileLocation,
privateKeyLocation,
privateKeyPassword,
decryptedOutput); Console.WriteLine("File decrypted to :" + decryptedOutput);
Console.WriteLine("The original file name of the decrypted file was :" + originalFileName);
}
catch (PGPException e)
{
if (e is NonPGPDataException)
{
Console.WriteLine("The input file is not an OpenPGP archive or is corrupted");
}
else if (e is WrongPrivateKeyException)
{
// The message cannot be decrypted with this private key
// or the supplied private key is not an OpenPGP private key or is corrupted
Console.WriteLine(e.Message);
}
else if (e is WrongPasswordException)
{
Console.WriteLine("The password for the private key is incorrect");
}
else if (e is FileIsPBEEncryptedException)
{
Console.WriteLine("The input file is password encrypted.");
Console.WriteLine("You have to use DecryptAndVeifyFilePBE or DecryptAndVerifyStreamPBE");
}
else if (e is IntegrityCheckException)
{
Console.WriteLine("The encrypted data is corrupted");
}
else
{
Console.WriteLine(e.Message);
}
}

EnryptFileToExe

         // initialize the SFX generator class
SfxCreator sfx = new SfxCreator(); // encrypt the data file and create an executable
sfx.EnryptFileToExe(@"input2.txt", "644611", @"input2.exe");

key.store

// initialize the KeyStore
// If the keystore file does not exists, it is created.
KeyStore ks = new KeyStore(@"key.store", "changeit"); String userId = "support@didisoft.com";
if (!ks.ContainsKey(userId))
{
// Generate RSA based OpenPGP key with predefined parameters;
// for more customized generation see GenerateKeypairRSA.cs
// (Note: the predefined key parameters here are the same as in PGP Desktop version 10)
ks.GenerateKeyPair(2048, "support@didisoft.com", "changeit");
}
ks.ExportPublicKey("mypb.txt", userId, true);
ks.ExportPrivateKey("mypv.txt", userId, true);
MessageBox.Show("ok");

  // create an instance of the library
PGPLib pgp = new PGPLib(); // Import the main company public key
// pgp.AddMasterKey(@"xx.asc"); // after the encryption the output file will be encrypted with two keys
pgp.EncryptFile(@"input.txt", @"mypb.txt", @"input_ks.txt.pgp");
MessageBox.Show("杀杀杀");

 // create an instance of the library
PGPLib pgp = new PGPLib(); //pgp.DecryptFile(@"input_ks.txt.pgp", @"mypv.txt", "changeit", @"input_ks.txt"); KeyStore ks = new KeyStore(@"key.store", "changeit");
pgp.DecryptFile(@"input_ks.txt.pgp",ks, "changeit", @"input_ks.txt");
MessageBox.Show("杀杀杀");

  

OpenPGP Library v.1.7
http://www.winsite.com/Development/Components-Libraries/OpenPGP-Library-for-NET/

http://bbs.csdn.net/topics/390267637
Bin】下的【BouncyCastle.CryptoExt.dll】和【DidiSoft.Pgp.dll】引用到项目中,就可以很方便的在C#中使用PGP加解密了。

https://www.didisoft.com/net-openpgp/examples/decrypt-and-verify/
https://www.didisoft.com/net-openpgp/

https://www.componentsource.com/product/openpgp-library-for-dotnet

http://www.pgp.cn/index.htm

open_vPGPv的更多相关文章

随机推荐

  1. Linux 文件压缩、打包

    文件压缩 计算机使用byte单位来计量.实际上,计算机最小的计量单位是bit.1byte = 8 bit.如果记录1这个数字,00000001,1会在最右边占一个1个bit 其他7个bit会被填上0. ...

  2. 升级ruby的版本 https://gems.ruby-china.com/

    升级ruby版本,有时候安装ruby的版本过低,需要进行升级,例如安装在centos6.7安装fpm需要ruby版本在1.9以上. 1.主机环境如下: 1 [root@test ~]# cat /et ...

  3. C#中的断言(Assert)

    重构-断言 现象:某一段代码需要对程序状态做出某种假设 做法:以断言明确表现这种假设 动机: 常常有这种一段代码:只有某个条件为真是,该改名才能正常运行. 通常假设这样的假设并没有代码中明确表现出来, ...

  4. Cisco设备配置SSH登录

    一 试验拓扑 二 Server配置 ①配置hostname和domain name 因为rsa的秘钥是用hostname和domain name产生的 Router(config)#host Serv ...

  5. ios开发 需要注意的地方、注意事项

    /* 一.LaunchScreenLaunchScreen产生原因:代替之前的启动图片好处:1.可以展示更多的东西2.可以只需要出一个尺寸的图片. 启动图片的优先级启动图片 < LaunchSc ...

  6. 改进初学者的PID-测量的比例编码

    最近看到了Brett Beauregard发表的有关PID的系列文章,感觉对于理解PID算法很有帮助,于是将系列文章翻译过来!在自我提高的过程中,也希望对同道中人有所帮助.作者Brett Beaure ...

  7. Swift编码总结7

    1.Git 打Tag: 命令也就下面两条,看看就会了. 2.字符串转Model:JSONDecoder http://www.cocoachina.com/ios/20180612/23771.htm ...

  8. 系统运维工程师装逼完全指南(转载Mark)

    1.全球化的认证有助于提升逼格,什么OCM.CCIE.RHCA.CISSP等等能考都考,再不济,也要有一张系统架构设计师或者网络规划设计师的信产部认证.每过一个认证,逼格提升一档. 2.TCP/IP协 ...

  9. xshell的ssh连接频繁提示Socket error Event: 32 Error: 10053(待验证)

    修改/etc/ssh/sshd_config下的配置文件 将ClientAliveInterval的值修改为60 然后重启ssh服务器 目前没有在频繁出现ssh断开问题了,应该是有效的

  10. shell语法学习

    [原文] 菜鸟笔记shell教程学习. 本篇博客只是记录shell的一些关键语法,主要是做一个记录,有些内容也是copy过来的,并不是一个完整的教程,想完整学习shell的同学可以前往 shell脚本 ...