gpt4 book ai didi

sql-server-2005 - 所有用户的成员身份 SHA1 哈希值都不相同

转载 作者:行者123 更新时间:2023-12-04 04:53:14 27 4
gpt4 key购买 nike

我有一个纯文本的用户表并将其迁移到成员资格提供商。

使用 ColdFusion(当前系统),我设法对一个用户的密码(测试用户)进行了哈希处理,结果完美匹配。但现在后续用户不匹配。我做错了什么。

<cfscript>
theEncoding = "UTF-16LE";
thePassword = "dtD3v310p3r!";
base64Salt = "JZjdzUXREM0A7DPI3FV3iQ==";
theSalt = charsetEncode( binaryDecode(base64Salt, "base64"), theEncoding );
theHash = hash(theSalt & thePassword, "SHA1", theEncoding);

// hash always returns hex. convert it to base64 so it matches DNN
theBase64Hash = binaryEncode(binaryDecode(theHash, "hex"), "base64");
WriteOutput("<br />theBase64Hash= "& theBase64Hash &"<br/>");
WriteOutput("DBPassword= 5khDDMmoFtW+j99r/whE/TjyIUo= <br />");


theEncoding = "UTF-16LE";
thePassword = "DT!@12";
base64Salt = "+muo6gAmjvvyy5doTdjyaA==";
theSalt = charsetEncode( binaryDecode(base64Salt, "base64"), theEncoding );
theHash = hash(theSalt & thePassword, "SHA1", theEncoding);

// hash always returns hex. convert it to base64 so it matches DNN
theBase64Hash = binaryEncode(binaryDecode(theHash, "hex"), "base64");
WriteOutput("<br />theBase64Hash= "& theBase64Hash &"<br/>");
WriteOutput("DBPassword= nfcqQBgeAm0Dp1oGZI0O70Y6DvA= <br />");
</cfscript>

第一个工作 100%。但是第二个没有。
第二个产生的哈希值为 86SrPKXW5xywDYoC8MVy0q259sQ=

最佳答案

嗯.. 我认为当两个值连接时可能会出错。散列应该真正使用一个字节数组,like with the encrypt version ,可惜CF9的hash()函数不支持它 - 只有字符串。 (虽然记录很差,但它在 CF11 中得到支持)。我不确定是否有针对 CF9 的纯 CF 解决方法。但是,与此同时,您可以直接使用 java:

<cfscript>
thePassword = "DT!@12";
base64Salt = "+muo6gAmjvvyy5doTdjyaA==";

// extract bytes of the salt and password
saltBytes = binaryDecode(base64Salt, "base64");
passBytes = charsetDecode(thePassword, "UTF-16LE" );

// next combine the bytes. note, the returned arrays are immutable,
// so we cannot use the standard CF tricks to merge them
ArrayUtils = createObject("java", "org.apache.commons.lang.ArrayUtils");
dataBytes = ArrayUtils.addAll( saltBytes, passBytes );

// hash binary using java
MessageDigest = createObject("java", "java.security.MessageDigest").getInstance("SHA-1");
MessageDigest.update(dataBytes);
theBase64Hash = binaryEncode(MessageDigest.digest(), "base64");

WriteOutput("<br />theBase64Hash= "& theBase64Hash &"<br/>");
WriteOutput("DBPassword= nfcqQBgeAm0Dp1oGZI0O70Y6DvA= <br />");
</cfscript>

更新:

进一步环顾四周后,我认为没有纯 CF 解决方案。 UTF-16LE 编码只是问题的一部分。另一个问题是 DNN 分别解码每个字符串,这可能会产生与将两者解码为单个字符串时不同的字节(参见下面的比较)。它适用于您的第二个密码,这就是最终散列不同的原因。自 hash不会接受字节数组,我认为它不是这项工作的正确工具。 MessageDigest是要走的路。

字节数组比较
           old|   new | 
1 | -6 | -6 |
2 | 107 | 107 |
3 | -88 | -88 |
4 | -22 | -22 |
5 | 0 | 0 |
6 | 38 | 38 |
7 | -114 | -114 |
8 | -5 | -5 |
9 | -14 | -14 |
10 | -53 | -53 |
11 | -105 | -105 |
12 | 104 | 104 |
13 | -3 | 77 | **
14 | -1 | -40 | **
15 | 68 | -14 | **
16 | 0 | 104 | **
17 | 84 | 68 | **
18 | 0 | 0 |
19 | 33 | 84 | **
20 | 0 | 0 |
21 | 64 | 33 | **
22 | 0 | 0 |
23 | 49 | 64 | **
24 | 0 | 0 |
25 | 50 | 49 | **
26 | 0 | 0 |
27 | | 50 | **
28 | | 0 | **
  • old => charsetDecode( theSalt & thePassword, "UTF-16LE")
  • 新 => ArrayUtils.addAll( saltBytes, passBytes );
  • 关于sql-server-2005 - 所有用户的成员身份 SHA1 哈希值都不相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17111641/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com