加密

 // 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. element-ui里面的table插入多张图片

    <el-form-item label="身份证正反面" label-width="120px"> <section v-if="t ...

  2. 程序日志-应用程序-特定 权限设置并未向在应用程序容器 不可用 SID (不可用)中运行的地址 LocalHost (使用 LRPC) 中的用户 NT AUTHORITY\SYSTEM SID (S-1-5-18)授予针对 CLSID 为 {D63B10C5-BB46-4990-A94F-E40B9D520

    应用程序-特定 权限设置并未向在应用程序容器 不可用 SID (不可用)中运行的地址 LocalHost (使用 LRPC) 中的用户 NT AUTHORITY\SYSTEM SID (S-1-5-1 ...

  3. 帝国cms更换Ueditor编辑器上传图片加水印

    Ueditor安装包,里面有个/php/文件夹,找到Uploader.class.php,这是通用上传类文件找到private function upFile(),这是上传文件的主处理方法,找到122 ...

  4. unused function warning message(转)

    這篇的對象是 static function,static function 若沒有其它 function 去存取的話,在 compile 時,會發生 unused error,可以在 functio ...

  5. Centos7搭建FTP服务详细过程

    Centos7搭建FTP服务详细过程https://blog.csdn.net/sinat_30802291/article/details/81706152

  6. 《精通CSS第3版》(5)漂亮的盒子

  7. django后台list_display中添加自定义字段

    list_display = ("apply_prove",) def apply_prove(self, obj): : return "<a href='/' ...

  8. 不使用BASE64Encoder、BASE64Decoder

    BASE64Encoder/BASE64Decoder类在sun.misc包下,是sun公司的内部方法,后期有删除的潜在可能,建议使用apache commons.codec下的Base64替代. m ...

  9. C# .NET 私钥 RSA2,SHA256,签名

    私钥长度2048 -- /// <summary> /// 生成签名 /// </summary> /// <param name="str"> ...

  10. 使用 Node.js 写一个代码生成器

    背景 第一次接触代码生成器用的是动软代码生成器,数据库设计好之后,一键生成后端 curd代码.之后也用过 CodeSmith , T4.目前市面上也有很多优秀的代码生成器,而且大部分都提供可视化界面操 ...