open_vPGPv
加密
// 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的更多相关文章
随机推荐
- Android中LayoutInflater()方法
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...
- css文字两行或者几行显示省略号
做这个省略的问题,突然发现显示省略号是有中英文区分的 我做两行的时候用的是以下代码,在是中文的情况下是么得问题,到了英文下发现不起作用了 width: 250px; overflow: hidden; ...
- 为什么集合类没有实现Cloneable和Serializable接口
为什么集合类没有实现Cloneable和Serializable接口? 答:克隆(cloning)或者序列化(serialization)的语义和含义是跟具体的实现相关的.因此应该由集合类的具体实现类 ...
- python使用ldap3进行接口调用
把自己使用到的ldap调用的代码分享出来,希望大家可以参考 #!/usr/bin/python # -*- coding: utf-8 -*- """ @Time : 2 ...
- TCP Keepalive笔记
TCP是无感知的虚拟连接,中间断开两端不会立刻得到通知.一般在使用长连接的环境下,需要心跳保活机制可以勉强感知其存活.业务层面有心跳机制,TCP协议也提供了心跳保活机制. 长连接的环境下,人们一般使用 ...
- NLP自然语言处理
转:https://blog.csdn.net/qq_17677907/article/details/86448214 1.有哪些文本表示模型,它们各有什么优缺点? 文本表示模型是研究如何表示文 ...
- nmon报告分析
nmon结果说明及分析 2018年09月29日 16:12:10 Jio_2018 阅读数 2334 使用nmon analyser生成的结果文件包含了N多个sheet页,下面只是结合个人经验对几 ...
- 爬虫urllib2库的基本使用
所谓网页抓取,就是把URL地址中指定的网络资源从网络流中读取出来,保存到本地. 在Python中有很多库可以用来抓取网页,urllib2库基本使用. urllib2 是 Python2.7 自带的模块 ...
- git bush 无法使用箭头进行选择
1 找到git bash 的安装目录,找到bash.bashrc文件, 2 在文件的尾部加上:alias vue='winpty vue.cmd', 3 重启git bash 即可 来自:https: ...
- ajax中参数traditional的作用
在使用ajax向后台传值的时候,有的时 $.ajax({ type: "post", async: true, data: { "records": [&quo ...