https://www.cnblogs.com/xiaochu/p/4402195.html
MD5加密字符串并轉(zhuǎn)化為base64(C#和PHP代碼相同實(shí)現(xiàn))
-------PHP------代碼-------------
function Md5Base64($data)
{
$md5hex=md5($data);
$len=strlen($md5hex)/2;
$md5raw="";
for($i=0;$i<$len;$i++) { $md5raw=$md5raw . chr(hexdec(substr($md5hex,$i*2,2))); }
$keyMd5=base64_encode($md5raw);
return $keyMd5;
}
---------C#=----------------------
public static string MD5ToBase64String(string str)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] MD5 = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str));//MD5(注意UTF8編碼)
string result = Convert.ToBase64String(MD5, 0, MD5.Length);//Base64
return result;
}
聯(lián)系客服