Coldfusion 和 java 加密函数
在尝试将用户语音的令牌生成器从java转换为coldfusion时,我注意到java中的哈希函数执行coldfusion中的哈希函数:
String salted = "63bfb29835aedc55aae944e7cc9a202dmbdevsite";
byte[] hash = DigestUtils.sha(salted);
给出= [-19, -18, 7, 92, -121, 13, 88, 68, - 84, 61, -77, -20, -85, -102, -102, -62, -70, 45, -16, 18]
<cfset Salted="63bfb29835aedc55aae944e7cc9a202dmbdevsite" />
<cfset hash=Hash(Salted,"SHA") />
<cfset arrBytes = hash.GetBytes() />
给出= 69686969485553675655486853565252656751686651696765665765576567506665506870484950
谁能解释一下?
谢谢
while trying to translate token generator for uservoice from java to coldfusion, I noticed the the hash function in java does the one in coldfusion :
String salted = "63bfb29835aedc55aae944e7cc9a202dmbdevsite";
byte[] hash = DigestUtils.sha(salted);
gives = [-19, -18, 7, 92, -121, 13, 88, 68, -84, 61, -77, -20, -85, -102, -102, -62, -70, 45, -16, 18]
<cfset Salted="63bfb29835aedc55aae944e7cc9a202dmbdevsite" />
<cfset hash=Hash(Salted,"SHA") />
<cfset arrBytes = hash.GetBytes() />
gives = 69686969485553675655486853565252656751686651696765665765576567506665506870484950
Can anyone explain this ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您实际上得到了相同的结果,但是输出的编码不同。对于 Java,它是一个字节数组,需要注意的是
byte
是有符号的。对于 ColdFusion,您将获得十六进制,由于某种原因,每个十六进制字符以十进制格式输出。如果您查看 http://asciitable.com/ 并将十进制数字映射到其字符(例如 69 到 E, 68 到 D,48 到 0),您会得到:哈希结果通常存储为十六进制。如果将 Java 版本编码为十六进制,您将得到相同的结果:
You are actually getting the same result, however the outputs are encoded differently. For Java it's a byte array, and it's important to note that
byte
is signed. For ColdFusion you're getting hex that for some reason is outputted in decimal format for each hex character. If you look at http://asciitable.com/ and map the decimal numbers to their characters (e.g. 69 to E, 68 to D, 48 to 0), you get:Hashed results are often stored as hex. If you encode the Java version into hex, you'll get the same:
您可以使用 BinaryDecode 来获取与 Java Hash 相同的字节数组。
You can use BinaryDecode to get the same byte array as the Java Hash.