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

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 } }


相关文章:
MD5加密解密算法的描述
MD5加密解密算法的描述_计算机软件及应用_IT/计算机_专业资料 暂无评价|0人阅读|0次下载|举报文档 MD5加密解密算法的描述_计算机软件及应用_IT/计算机_专业资料。...
MD5暴力破解
5.点击“加密或校验”按钮对明文加密,密文将呈现在“生成的 MD5 密文”文本框中。 E10ADC3949BA59ABBE56E057F20F883E 就是 MD5 密文。 学习 MD5 暴力破解...
MD5加密解密类(Java)
MD5加密解密类(Java)_IT/计算机_专业资料。一个上Java培训课时写的MD5加密解密类package com.zyg.security.md5; import import import import import java.io.Un...
Md5加密算法的原理及应用
RIPEMD 算法的报告,公布了 MD 系列算法的破解结果,MD5 破解工程权威网站 (http://www.md5crk.com)也因此关闭,从此宣布 MD5 加密算法不再是一种安全的加密算法...
实验7 MD5暴力破解
由于 MD5 加密实际上是一种不可逆的加密手段,现实中的 MD5 破解其实是将字典 档内容来逐个 MD5 加密后, 使用加密后的密文比对需要破解的密文, 如果相同则破解...
md5加解密
md5 加密解密 2009-03-11 03:34 一个例子 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.security...
php自带加密解密函数
php 自带加密解密函数 2011-11-01 09:57 2121 人阅读 评论(0) 收藏 举报 加密解密 phpstringunix 网络 不可逆的加密函数为:md5()、crypt() md5() 用来计算...
C#编写的MD5、AES等算法的加密解密
3 实验步骤 3.1 Form 窗体 六个菜单栏:MD5 加密,DES 加密解密,Triple DES 加密解密,RC2 加密解密,AES 加密解密,RSA 加密解密,分别对应相应的算法。 代码: ...
Md5(VavicApp)加密解密
Md5(VavicApp)加密解密_计算机软件及应用_IT/计算机_专业资料。md5加密解密(C#源码) Md5 加密解密 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)为...
加密解密原理
公钥私钥加解密原理: 1.首先, 我们用单向加密算法将一个数据包用 MD5 算法算出校验码, MD5 校验码很短, 只有 128 位,然后再用自已私钥加密这段 MD5 校验码...
更多相关标签: