MD5 encrypted string and converted to base64 (C # is the same as PHP code)

Source: Internet
Author: User
Encrypt the MD5 string and convert it to base64 (C # is the same as PHP code). convert the MD5 encrypted string to base64 (C # is the same as PHP code)

------- PHP ------ code -------------
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 (pay attention to UTF8 Encoding)
String result = Convert. ToBase64String (MD5, 0, MD5.Length); // Base64
Return result;
}

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.