C#???ü??????
???????????? ???????[ 2013/8/13 10:48:54 ] ????????
????MD5????
/// <summary>
/// MD5????
/// </summary>
/// <param name="content">??????????</param>
/// <returns>?????????????</returns>
public static string EncodeMD5(string content)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.Default.GetBytes(content);//????????????????????
byte[] md5data = md5.ComputeHash(data);//????data???????????
md5.Clear();
string str = "";
for (int i = 0; i < md5data.Length - 1; i++)
{
str += md5data[i].ToString("x").PadLeft(2?? '0');
}
return str;
}
????DES?????????
//?????????? (Key) ?????????? (IV) ???????????????? (DES) ??????????
static byte[] desKey=Encoding.UTF8.GetBytes("12345678")?? iv=Encoding.UTF8.GetBytes("12345678");
/// <summary>
/// ????
/// </summary>
/// <param name="content">??????????</param>
/// <returns>????</returns>
public static string Encode(string content)
{
//??????
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//???????????????????????
byte[] contentArray = Encoding.UTF8.GetBytes(content);
//??????м???
MemoryStream ms = new MemoryStream();
//??????
CryptoStream cs = new CryptoStream(ms?? des.CreateEncryptor(desKey?? iv)?? CryptoStreamMode.Write);
//???? ??д??????
cs.Write(contentArray?? 0?? contentArray.Length);
//????????
cs.FlushFinalBlock();
//??????
return Convert.ToBase64String(ms.ToArray());
}
/// <summary>
/// ????
/// </summary>
/// <param name="password">????</param>
/// <returns>??????????</returns>
public static string Decode(string password)
{
if (string.IsNullOrEmpty(password))
{
return "";
}
//??????
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//?????????????????? ?????????????????????base64string ?????????base64string????????????
byte[] passwordArray = Convert.FromBase64String(password);
//??????н???
MemoryStream ms = new MemoryStream(passwordArray);
//??????
CryptoStream cs = new CryptoStream(ms?? des.CreateDecryptor(desKey?? iv)?? CryptoStreamMode.Read);
//?? ?????????????н????????
StreamReader reader = new StreamReader(cs);
//??????
return reader.ReadToEnd();
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11