简体   繁体   中英

PHP MD5 hashing

i have a hashing algorithm in C#, in a nutshell, it is:

string hashCode = string.Empty;
        if (null != password)
        {
            System.Security.Cryptography.MD5 cryptography = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] code = cryptography.ComputeHash(Encoding.Default.GetBytes(password));
            StringBuilder stringBuilder = new StringBuilder();

            // Converting the code to string.
            for (int i = 0; i < code.Length; i++)
            {
                stringBuilder.Append(code[i].ToString("x2"));
            }

            hashCode = stringBuilder.ToString();
        }

        return hashCode;
    }

Now I need to replicate this behaviour in php..... Thanks in advance...

NOTE: I cannot change C# behaviour because it's already implemented and passwords saved in my db with this algorithm.

PHP has built in MD5 ability, you can put about anything in and get a hex string back, is this what you had in mind?

md5()

http://php.net/manual/en/function.md5.php

SEE BELOW

PHP中的加密

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM