加密

 // 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

最新文章

  1. java并发编程(十七)Executor框架和线程池
  2. 算法系列:HMM
  3. Visual Studio工具——为编辑器增加垂直辅助线
  4. magento和discuz(ucenter)整合集成开发思路
  5. C++ 为什么要用覆盖(学习笔记)
  6. 利用Unicorn和Idaemu辅助解决Geekpwn SecretCode
  7. Windows 8.1 正式版微软官方原版镜像下载(新增10/17新版下载)
  8. Spring的后置处理器BeanPostProcessor
  9. linux内核开发入门学习
  10. Kafka基本架构及原理
  11. python---random模块详解
  12. lombok 工具类的介绍
  13. Spring 7种事务传播行为
  14. 算法笔记_215:第六届蓝桥杯软件类校赛部分真题(Java语言B组)
  15. JDK1.6新特性,WebService强化
  16. (asp)JScript读写、复制、移动文件 asp也就那回事(4)
  17. CodeForces - 547D: Mike and Fish (转化为欧拉回路)(优化dfs稠密图)(定向问题)
  18. KVM libvirt的CPU热添加
  19. mysql 取当前日期对应的周一或周日
  20. 初识GeneXus产品

热门文章

  1. 【POJ3083】Children of the Candy Corn
  2. Markdown 打出上下标
  3. conda中重要的三个概念:环境、通道和包
  4. 如何在IDEA上配置Maven
  5. MySQL免安装配置步骤
  6. 【转】理解Docker容器网络之Linux Network Namespace
  7. .NET Core Startup启动类
  8. 最近b站好像把blv格式换成m4s,改成mp4之后没有声音,
  9. git - gitHub生成Markdown目录
  10. Java 使用ZkClient操作Zookeeper