C# 和 Python 的 hash_md5加密方法
一、C# 和 Python 的 hash_md5加密
1、C#版本1
public static string GenerateMD5Hash(string str)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] byteArray = Encoding.UTF8.GetBytes(str);
byteArray = md5.ComputeHash(byteArray);
string hashedValue = "";
foreach (byte b in byteArray)
{
hashedValue += b.ToString("x2");
}
return hashedValue;
}
2、C#版本2
public static string GenerateMD5Hash(string str)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] byteArray = Encoding.UTF8.GetBytes(str);
byteArray = md5.ComputeHash(byteArray);
StringBuilder mdStrBuff = new StringBuilder();
for (int i = 0; i < byteArray.Length; i++)
{
if ((0xFF & byteArray[i]).ToString("x").Length == 1)
{
mdStrBuff.Append("0");
}
mdStrBuff.Append((0xFF & byteArray[i]).ToString("x"));
}
string r = mdStrBuff.ToString();
return r;
}
3、Python版本
def hash_md5(s):
res = s
h = hashlib.md5()
h.update(res.encode(encoding='utf-8'))
return h.hexdigest()
到此這篇關(guān)于C# 和 Python 的 hash_md5加密方法的文章就介紹到這了,更多相關(guān)C# 和 Python 的 hash_md5加密內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Http Head方法獲取文件長(zhǎng)度的實(shí)現(xiàn)方法詳解
本篇文章是對(duì)使用Http Head方法獲取文件長(zhǎng)度的實(shí)現(xiàn)方法進(jìn)行詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
Winform實(shí)現(xiàn)抓取web頁(yè)面內(nèi)容的方法
這篇文章主要介紹了Winform實(shí)現(xiàn)抓取web頁(yè)面內(nèi)容的方法,代碼只有短短幾行,但是功能很實(shí)用,需要的朋友可以參考下2014-09-09
Unity實(shí)現(xiàn)物體運(yùn)動(dòng)時(shí)畫(huà)出軌跡
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)物體運(yùn)動(dòng)時(shí)畫(huà)出軌跡,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
C#winform中數(shù)據(jù)庫(kù)綁定DataGrid的實(shí)現(xiàn)
本文主要介紹了C#winform中數(shù)據(jù)庫(kù)綁定DataGrid的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
利用Distinct()內(nèi)置方法對(duì)List集合的去重問(wèn)題詳解
這篇文章主要給大家介紹了關(guān)于利用Distinct()內(nèi)置方法對(duì)List集合的去重問(wèn)題的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06

