当前位置:首页 >> 电力/水利 >>

MD5解密加密


// ?? ??: ??????????????×÷?à???á????????????×÷???ù?????? using System; using System.IO; using System.Text; using System.Security.Cryptography; namespace CClassLibrary.Rule { /// <summary> /// CCryptography ?????????÷?? /// </summary> public class CCryptography { /// <summary> /// ??·¨???ú?????? /// </summary> protected string mstrv_CryptKey ="!@#$%+|+)!#$%!@#adfasdf)89083049123)(*&^@#$%@#$%"; /// <summary> /// ??·¨?????????ò?? /// </summary> protected string mstrv_CryptIV = "!@adff2324gfh)asdf12dfasdf)89083049123)(*&^@#$%@#$%"; //================================================================ =================================== // 2006-11-28 megan ???? /// <summary> /// ?????é?¤??·¨???ú?????? /// </summary> protected string mstrv_SecdCryptKey ="!@#$%+|+)!#$%!@#asdfasdf)123456456)(*&^@#$%@#$%"; /// <summary> /// ?????é?¤??·¨?????????ò?? /// </summary> protected string mstrv_SecdCryptIV = "!@adff2324gfh)adfasfsdfa3)1234567487)(*&^@#$%@#$%"; //================================================================ =================================== /// <summary> /// ??????????????×÷?à /// </summary>

public CCryptography() { mstrv_CryptKey = "!@#$%+|+)!#$%!@#adfasdf)89083049123)(*&^@#$%@#$%".Substring(0,32) ; mstrv_CryptIV = "!@adff2324gfh)asdf12dfasdf)89083049123)(*&^@#$%@#$%".Substring(0, 16); } #region [Encrypt,Decrypt] public function //·?·¨ //????·?·¨ /// <summary> /// ????·?·¨ /// </summary> /// <param name="sCryptText"></param> /// <param name="sCryptKey"></param> /// <param name="sCryptIV"></param> /// <returns></returns> public string Encrypt( string sCryptText, sCryptKey,string sCryptIV) { RijndaelManaged des = new RijndaelManaged(); //°?×?·???·???byte??×é?? //?-????????UTF8±à??????????Unicode±à?????????? byte[] inputByteArray Encoding.Default.GetBytes(sCryptText); //byte[] inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);

string

=

//?¨?????????ó?????????????? //?-??????ASCIIEncoding.ASCII·?·¨??GetBytes·?·¨ //????????????±?????????????±? des.Key = ASCIIEncoding.ASCII.GetBytes(sCryptKey); des.IV = ASCIIEncoding.ASCII.GetBytes(sCryptIV); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),CryptoStreamMode.Write); //Write the byte array into the crypto stream //(It will end up in the memory stream) cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock();

//Get the data back from the memory stream, and into a string StringBuilder ret = new StringBuilder(); foreach(byte b in ms.ToArray()) { //Format as hex ret.AppendFormat("{0:X2}", b); } ret.ToString(); return ret.ToString(); } //????·?·¨ public string Decrypt(string sCryptText, sCryptKey,string sCryptIV) { RijndaelManaged des = new RijndaelManaged();

string

//Put the input string into the byte array byte[] inputByteArray = new byte[sCryptText.Length / 2]; for(int x = 0; x < sCryptText.Length / 2; x++) { int i = (Convert.ToInt32(sCryptText.Substring(x * 2, 2), 16)); inputByteArray[x] = (byte)i; } //?¨?????????ó?????????????????????????????????? des.Key = ASCIIEncoding.ASCII.GetBytes(sCryptKey); des.IV = ASCIIEncoding.ASCII.GetBytes(sCryptIV); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(),CryptoStreamMode.Write); //Flush the data through the crypto stream into the memory stream cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); //Get the decrypted data back from the memory stream //?¨??StringBuild???ó??CreateDecrypt?????????÷???ó??±???°?????? ó????±?±????÷???ó StringBuilder ret = new StringBuilder(); return

System.Text.Encoding.Default.GetString(ms.ToArray()); } #endregion #region [Encrypt,Decrypt] satatic function /// <summary> /// ×?·??????? /// </summary> /// <param name="sCryptText">?è?????????-×?·???</param> /// <returns>?????ó??×?·???</returns> public static string Encrypt( string sCryptText ) { CCryptography csCrypt = new CCryptography(); return csCrypt.Encrypt(sCryptText,csCrypt.mstrv_CryptKey,csCrypt.mstrv_Cr yptIV ); } /// <summary> /// ×?·??????? /// </summary> /// <param name="sCryptText">?è????????????×?·???</param> /// <returns>?????ó??×?·???</returns> public static string Decrypt( string sCryptText ) { CCryptography csCrypt = new CCryptography(); return csCrypt.Decrypt( sCryptText,csCrypt.mstrv_CryptKey,csCrypt.mstrv_C ryptIV ); } /// <summary> /// ?????é?¤×?·??????? /// </summary> /// <param name="sCryptText">?è?????????-×?·???</param> /// <returns>?????ó??×?·???</returns> public static string SecdEncrypt( string sCryptText ) { CCryptography csCrypt = new CCryptography(); return csCrypt.Encrypt(sCryptText,csCrypt.mstrv_SecdCryptKey,csCrypt.mstr

v_SecdCryptIV ); } /// <summary> /// ?????é?¤×?·??????? /// </summary> /// <param name="sCryptText">?è????????????×?·???</param> /// <returns>?????ó??×?·???</returns> public static string SecdDecrypt( string sCryptText ) { CCryptography csCrypt = new CCryptography(); return csCrypt.Decrypt( sCryptText,csCrypt.mstrv_SecdCryptKey,csCrypt.mst rv_SecdCryptIV ); } #endregion } }



相关文章:
加密解密基础知识
加密解密基础知识 一、加密的基础知识 1、对称性加密算法:AES,DES,3DES。 DES...通常在数据传输过程前,使用 MD5 和 SHA1 算法均需要发送和接收数据双方在数据...
Md5加密算法的原理及应用
RIPEMD 算法的报告,公布了 MD 系列算法的破解结果,MD5 破解工程权威网站 (http://www.md5crk.com)也因此关闭,从此宣布 MD5 加密算法不再是一种安全的加密算法...
实验7 MD5暴力破解
由于 MD5 加密实际上是一种不可逆的加密手段,现实中的 MD5 破解其实是将字典 档内容来逐个 MD5 加密后, 使用加密后的密文比对需要破解的密文, 如果相同则破解...
加密解密原理
公钥私钥加解密原理: 1.首先, 我们用单向加密算法将一个数据包用 MD5 算法算出校验码, MD5 校验码很短, 只有 128 位,然后再用自已私钥加密这段 MD5 校验码...
破解
2.通过 cmd5 网站生成 md5 密码在浏览器中输入地址“http://www.cmd5.com/”,在 输入框中输入想要加密的原始密码,然后单击“md5 加密解密”按钮即可。 4....
课常见各种加密解密方法详解
加密解密方法详解讲师:wjs 学习目标: 1:*星号密码的破解方法 *号密码查看器或 aio -unhide 2:md5 16 位 32 位 40 位的加密解密 破解技巧 40 位 MD5 = ...
MD5封装基本方法
MD5封装基本方法_计算机软件及应用_IT/计算机_专业资料。MD5封装基本方法 package com.zd.util; import java.security.MessageDigest; /** * 采用 MD5 加密解密 ...
Sql版加密解密函数
Sql版加密解密函数_计算机软件及应用_IT/计算机_专业资料。Sql版加密解密函数using...{ string Rst = ""; MD5CryptoServiceProvider MD = new MD5CryptoService...
JAVA 的MD5加密算法源代码
("原字符串:"); System.out.println(inbut); System.out.print("MD5 加密字符串:"); System.out.println(outbut); System.out.println("+++"); } } ...
C#编写的MD5、AES等算法的加密解密
3 实验步骤 3.1 Form 窗体 六个菜单栏:MD5 加密,DES 加密解密,Triple DES 加密解密,RC2 加密解密,AES 加密解密,RSA 加密解密,分别对应相应的算法。 代码: ...
更多相关标签: