MD5 encrypt strings and convert to Base64 (same implementation as C # and PHP code)

Source: Internet
Author: User

MD5 encrypt strings and convert to Base64 (same implementation as C # and PHP code)

-------PHP------Code-------------
function Md5base64 ($data)
{
$MD 5hex=md5 ($data);
$len =strlen ($MD 5hex)/2;
$MD 5raw= "";
for ($i =0; $i < $len; $i + +) {$md 5raw= $md 5raw. chr (Hexdec (substr ($md 5hex, $i *2,2)));}

$keyMd 5=base64_encode ($md 5raw);

return $keyMd 5;
}

---------c#=----------------------

public static string md5tobase64string (String str)
{
MD5 MD5 = new MD5CryptoServiceProvider ();
byte[] MD5 = Md5.computehash (System.Text.Encoding.UTF8.GetBytes (str));//MD5 (note UTF8 encoding)
string result = Convert.tobase64string (MD5, 0, MD5. Length);//base64
return result;
}

MD5 encrypt strings and convert to Base64 (same implementation as C # and PHP code)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.