为什么这些不一样?
PHP:
$hash = hash('sha256',$userData['salt'] . hash('sha256',$password) );
C#
public static string ComputeHash(string plainText,string salt) { // Convert plain text into a byte array. byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); byte[] saltBytes = Encoding.UTF8.GetBytes(salt); SHA256Managed hash = new SHA256Managed(); // Compute hash value of salt. byte[] plainHash = hash.ComputeHash(plainTextBytes); byte[] concat = new byte[plainHash.Length + saltBytes.Length]; System.Buffer.Blockcopy(saltBytes,concat,saltBytes.Length); System.Buffer.Blockcopy(plainHash,saltBytes.Length,plainHash.Length); byte[] tHashBytes = hash.ComputeHash(concat); // Convert result into a base64-encoded string. string hashValue = Convert.ToBase64String(tHashBytes); // Return the result. return hashValue; }
C#正在输出一个base64生态编码的字符串,PHP正在输出十六进制数.更好的比较可能是将参数true传递给PHP和base64的hash函数的结尾:
$hash = base64_encode( hash('sha256',$password),true ) );
原文地址:https://www.jb51.cc/php/131834.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。