-
php代码实现.Text密码加密方式
今日在转换.Text数据到php平台,需要用到用户密码的问题。
1234
.Text里是:0F-03-75-84-C9-9E-7F-D4-F4-F8-C5-95-50-F8-F5-07
php里md5是:81dc9bdb52d04dc20036dbd8313ed055
差的还够远的,.Text里面在md5前还Unicode一把。
注:我不得不承认M$在多字节编码中做的是在是好,从98以后开始,统一平台,应用程序都不存在编码问题,MSSQL用的一点问题都没,反看Php、MySQL编码问题都头大了。网上都没有现成的代码,还是在php手册里看到一句话:
If you are trying to emulate the UnicodeEncoding.Unicode.GetBytes() function in .NET, the encoding you want to use is: UCS-2LE
URL:http://cn2.php.net/manual/en/ref.mbstring.php#70294
莫大的启发啊。php要支持:Multibyte String,mbstring哦。
.Text密码加密方式:password = password.ToLower(); Byte[] clearBytes = new UnicodeEncoding().GetBytes(password); Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);php代码实现:
strtoupper(substr(chunk_split(md5(mb_convert_encoding(strtolower($password), 'UCS-2LE')), 2, '-'), 0, -1));