#region ========MD5加密========
public string MD5Encryption(string userPassword)
{
string MD5EncrypPassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(userPassword, "MD5");//202CB962AC59075B964B07152D234B70
return MD5EncrypPassword;
}
#endregion
#region ========SHA1加密========
public string SHA1Encryption(string userPassword)
{
string SHA1EncrypPassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(userPassword, "SHA1");
return SHA1EncrypPassword;
}
#endregion
#region ========DES加密========
public string DESEncryption(string userPassword,byte[] Key,byte[] Iv)
{
Byte[] password = Encoding.ASCII.GetBytes(userPassword);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream();
ICryptoTransform iCryrt = des.CreateEncryptor(Key, Iv);
CryptoStream cs = new CryptoStream(ms, iCryrt, CryptoStreamMode.Write);
cs.Write(password, 0, userPassword.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
#endregion
#region ========TripleDES加密========
public string TripleEncryption(string userPassword, string Key)
{
byte[] bytes = Encoding.Unicode.GetBytes(userPassword);
byte[] keys = ASCIIEncoding.ASCII.GetBytes(Key);
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
tripleDES.Key = keys; //长度必须为16位或则是24位
tripleDES.Mode = CipherMode.ECB; //设置运算模式
ICryptoTransform transform= tripleDES.CreateEncryptor();
return Convert.ToBase64String(transform.TransformFinalBlock (bytes, 0, bytes.Length));
}
#endregion
static void Main(string[] args)
{
string password = "123";
Byte[] key={12,23,34,45,56,20,35,12};
Byte[] iv={120,230,110,50,30,11,12,13};
string tt = "1234567890123456";
Encryptions ss = new Encryptions();
//string dnPword = ss.DESEncryption(password, key, iv);
string ds = ss.TripleEncryption(password, tt);
}