我正在尝试实现(远程)WordPress登录名的“简单”版本。
我到现在为止,但是当涉及到WordPress算法来加密密码时,我有点卡住了。来自“ class-phpass.php”的此代码段(WP用于哈希密码)...
$hash = md5($salt . $password, TRUE);
do {
$hash = md5($hash . $password, TRUE);
} while (--$count);
根据PHP 5手册-
string md5 ( string $str [, bool $raw_output = false ] )
“如果可选的raw_output设置为TRUE,则将以长度为16的原始二进制格式返回md5摘要。”]
到目前为止,要在C#中实现此目的,我正在使用下面的代码,可以找到here:
public string Md5Sum(string strToEncrypt) { System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding(); byte[] bytes = ue.GetBytes(strToEncrypt); // encrypt bytes MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] hashBytes = md5.ComputeHash(bytes); // Convert the encrypted bytes back to a string (base 16) string hashString = ""; for (int i = 0; i < hashBytes.Length; i++) { hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0'); } return hashString.PadLeft(32, '0'); }
如您所见,此C#版本与PHP版本等效,但是传入FALSE作为第二个参数。我已经通过比较两个版本的输出进行了检查。
此外,WordPress版本通过TRUE。我正在努力将此更改应用于C#版本。
以下PHP代码的C#等效项是什么?
$hash = md5($salt . $password, TRUE);
我正在尝试实现(远程)WordPress登录名的“简单”版本。到目前为止,我已经走了,但是当涉及到WordPress算法来加密密码时,我有点卡住了。此代码...