加密

 // 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. App数据指标

    App数据指标 1 App数据指标 2 参考资料 超详细的APP数据指标体系分析

  2. 使用IDEA查看变量调用链

    在开发中,我们有时需要查看某个变量是怎么来的,从哪个类的某个方法调用后进入另一个类的某个方法. 如果只有一两层的调用,那么还能直接通过方法跳转来观察. 但是,如果有七八层的调用链呢,在各个方法之间跳来 ...

  3. $(window).load()方法的使用场景

    一.$(window).load().window.onload=function(){}和$(document).ready()方法的区别 1.$(window).load() 和window.on ...

  4. sparkUI

    sparkUI 源码: https://www.cnblogs.com/barrenlake/p/4364644.html 页面介绍: https://blog.csdn.net/qq_2763977 ...

  5. 20189220 余超《Linux内核原理与分析》第三周作业

    操作系统如何工作的 第二章的基础知识 计算机的三大法宝:存储程序计算机,函数调用堆栈机制,中断. 堆栈:堆栈是C语言程序运行时必须使用的几率函数条用路径和参数存储的空间,具体作用分为:记录函数条用的框 ...

  6. javaagent使用指南

    今天打算写一下 Javaagent,一开始我对它的概念也比较陌生,后来在别人口中听到 字节码插桩,bTrace,Arthas后面才逐渐了解到Java还提供了这么个工具. JVM启动前静态Instrum ...

  7. go -- go 程序 启动docker容器

    package main import ( "io" "log" "os" "time" "github.co ...

  8. (二)OpenCV-Python学习—对比度增强

    ·对于部分图像,会出现整体较暗或较亮的情况,这是由于图片的灰度值范围较小,即对比度低.实际应用中,通过绘制图片的灰度直方图,可以很明显的判断图片的灰度值分布,区分其对比度高低.对于对比度较低的图片,可 ...

  9. IDEA2019.2中文字体变粗缺字等问题

    idea的中文字体渲染问题 IDEA 2018.2升级到 IDEA 2019.2,中文字体渲染问题修改一下备用字体就可以共需要修改两处:1.Setting -> Editor -> Fon ...

  10. Activiti task claim

    Activiti task claim claim,认领,领取 claim - 国内版 Bing https://cn.bing.com/search?FORM=U227DF&PC=U227& ...