Home >Backend Development >PHP Tutorial >MD5加密字符串并转化为base64(C#和PHP代码相同实现)

MD5加密字符串并转化为base64(C#和PHP代码相同实现)

WBOY
WBOYOriginal
2016-06-23 13:37:061433browse

MD5加密字符串并转化为base64(C#和PHP代码相同实现)

-------PHP------代码-------------
function Md5Base64($data)
{
$md5hex=md5($data);
$len=strlen($md5hex)/2;
$md5raw="";
for($i=0;$i
$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;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn