数字加密算法的封装
最近整理封装了一组数字加密算法,知识来源互联网,把各个零散的加密算法整在了一起,这样用起来比较方便。
不知道博客园怎样上传文件,喜欢的朋友可以发邮件给我素要源代码。邮箱:mail.ktgroup@gmail.com
下面我贴上一些使用说明:
【文档名:KT.Cryptography使用说明】
【创建人:K】
【文档创建时间:2010-2-3】
KT.Cryptography使用说明
一.CyptoType 枚举类型
TripleDES:DES三重对称加密算法
DES:对称加密算法
RSA:非对称加密算法
MD5:散列算法
SHA1:散列算法
二.DigitalSignManager 数字签名管理类,使用之前需要实例化
1. TripleDES 与 DES
对称加密算法,必须提供(密钥,IV向量)
A. 生成DES密钥,IV向量
DigitalSignManager DM = new DigitalSignManager(CyptoType.TripleDES);
密钥:DM.PublicKey 或者 DM.PrivateKey
IV向量: DM.IV
B. 加,减密
DigitalSignManager DM = new DigitalSignManager(CyptoType.TripleDES);
DM.PrivateKey = DM.PublicKey = “RHJGHIKJ++JHKKJKK”;
DM.IV = “ERTYUI++”;
DM.Encryp(“需要加密的字符串”) ;
DM.Decrypt( “需要减密的字符串” );
2. RSA
RSA非对称加密算法,必须(PublicKey,PrivateKey)
A. 生成PublicKey 与 PrivateKey
DigitalSignManager DM = new DigitalSignManager(CyptoType.RSA);
公钥:DM.PublicKey
私钥: DM.PrivateKey
B. 加密
DigitalSignManager DM = new DigitalSignManager(CyptoType.RSA);
DM.PublicKey = “FHGJKLTYGUHIO+++==IOGHJH”;
DM.Encryp(“需要加密的字符串”) ;
C. 减密
DigitalSignManager DM = new DigitalSignManager(CyptoType.RSA);
DM.PrivateKey = “FHGJKLTYGUHIO+++==IOGHJH”;
DM. Decrypt (“需要减密的字符串”) ;
3. MD5 与 SHA1
DigitalSignManager DM = new DigitalSignManager(CyptoType. MD5);
DM.Encrypt(“需要计算散列的字符串”)
三.数字摘要
生成Hash摘要(SHA1)函数签名
string signedData = HashAndSign(string dataToSign, string privateKey)
验证Hash摘要函数签名
bool VerifySignedHash(string dataToVerify, string signedData, string publicKey)
Sample:
//string enStr = “gthjkl;fdasfkljdaskljflsdjaldfkjlds”;
//string hash = DM.HashAndSign(enStr, DM.PrivateKey);
//Console.WriteLine(hash);
//Console.WriteLine(DM.VerifySignedHash(enStr,hash, DM.PublicKey));

浙公网安备 33010602011771号