再来个封装得更好的RSAHelper
2016-04-12 00:09
501 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Cn.Ubingo.Security.RSA.Core; using Cn.Ubingo.Security.RSA.Data; using Cn.Ubingo.Security.RSA.Key; /// <summary> /// 类说明:RSA类库,主要解决Net(c#)、ASN(Java)、PEM(PHP)三种格式相互转换使用的问题 /// 编码日期:2016-04-10 /// 编 码 人:TheLuther /// 引用网址:http://www.cnblogs.com/FoChen/p/4740814.html /// 修改日期:2016-04-10 /// </summary> class RSAHelper { public static KeyPair keypair = null; public static KeyPair PEM2XML(KeyPair PEMKeyPair, KeyPair XMLKeyPair) { return PEMKeyPair.ToXMLKeyPair(); } public static KeyPair ASN2XML(KeyPair ASNKeyPair, KeyPair XMLPair) { return ASNKeyPair.ToXMLKeyPair(); } public static KeyPair XML2PEM(KeyPair XMLKeyPair, KeyPair PEMKeyPair) { return XMLKeyPair.ToPEMKeyPair(); } public static KeyPair XML2ASN(KeyPair XMLPair, KeyPair ASNKeyPair) { return XMLPair.ToASNKeyPair(); } public static KeyPair CreatePair() { return KeyGenerator.GenerateKeyPair(); } public static string Encrypt(string data,string key,KeyFormat format) { KeyWorker worker = new KeyWorker(key, format); return worker.Encrypt(data); } public static string DeEncrypt(string data, string key, KeyFormat format) { KeyWorker worker = new KeyWorker(key, format); return worker.Decrypt(data); } public static void PEMDemo() { KeyPair pair = CreatePair().ToPEMKeyPair(); string data = "test"; KeyWorker worker = new KeyWorker(pair.PrivateKey,KeyFormat.PEM); string encryptdata = worker.Encrypt(data); worker = new KeyWorker(pair.PublicKey,KeyFormat.PEM); string deencryptdata = worker.Decrypt(encryptdata); } }
刚开始研究RSA的时候没注意,看到的大部分资料都是讲Cipher怎么用的,就忽视了这么好的一个东西了。这是自己对原博客内容的简单整理,用起来真是超爽,太方便了
相关文章推荐
- Centos 源码安装zabbix 2.4.5
- Java-线程池异常信息的坑
- poj 1985 Cow Marathon
- SQL基础语法笔记教程整理
- call,apply,bind
- oracle学习总结3
- 对象数组
- LayoutInflater的用法
- LOD优化
- poj 1144 Network 无向图求割点
- Hadoop实战第一篇
- UML学习(二)-----类图
- 安装arm-linux-gdb
- 初学java
- 在CentOS上安装GO运行环境及其开发工具LiteIDE
- 回顾 Firefox 历史
- ASP.NET创建三层架构图解详细教程
- ASP.NET 根据汉字获取汉字拼音的首字母(含多音字)
- 常用C#关键字详解教程(比较全面)
- 用Python写冒泡排序代码