问题描述
请帮助!我已经把我的头发拉过这一个。 :)
Please help! I have been pulling out my hair over this one. :)
我有一个网站,我需要HMAC SHA1进行身份验证。它目前使用另一种语言,但现在我需要移动到ColdFusion。对我的生活我不能得到的字符串匹配。 。任何援助将非常感激。
I have a site that I need to HMAC SHA1 for authentication. It currently works with another language but now I need to move it to ColdFusion. For the life of me I cannot get the strings to match. Any assistance would be much appreciated.
数据: HTTPS%3A%2F%2Fwww%2Etestwebsite%2Ecom%3Fid%3D5447
结果
键: 265D5C01D1B4C8FA28DC55C113B4D21005BB2B348859F674977B24E0F37C81B05FAE85FB75EA9CF53ABB9A174C59D98C7A61E2985026D2AA70AE4452A6E3F2F9
正确答案: WJD %2BKxmFxGWdbw4xQJZXd3%2FHkFQ%3D
结果
我的回答: knIVr6wIt6%2Fl7mBJPTTbwQoTIb8%3D
两者都是Base64编码,然后URL编码。
Both are Base64 encoded and then URL encoded.
推荐答案
做一个HMAC-SHA1的事情我自己。最好的我可以说是,我发现这个旧的功能。为我迄今为止做的工作伟大。忘记了,我发现它虽然所以我不能贷的作者。
Doing an HMAC-SHA1 thing myself. Best I can say is that I found this old function. Has worked great for what I am doing thus far. Forgot where I found it though so I can't credit the author.
有关您的基地64的东西...运行在您的加密这个功能,那么就做一个CFSET newString =上返回什么toBase64(oldString)
For your Base 64 stuff... run this function on your encryption, then just do a cfset newString = toBase64(oldString) on what is returned.
<cffunction name="hmacEncrypt" returntype="binary" access="public" output="false">
<cfargument name="signKey" type="string" required="true" />
<cfargument name="signMessage" type="string" required="true" />
<cfargument name="algorithm" type="string" default="HmacSHA1" />
<cfargument name="charset" type="string" default="UTF-8" />
<cfset var msgBytes = charsetDecode(arguments.signMessage, arguments.charset) />
<cfset var keyBytes = charsetDecode(arguments.signKey, arguments.charset) />
<cfset var keySpec = createObject("java","javax.crypto.spec.SecretKeySpec") />
<cfset var mac = createObject("java","javax.crypto.Mac") />
<cfset key = keySpec.init(keyBytes, arguments.algorithm) />
<cfset mac = mac.getInstance(arguments.algorithm) />
<cfset mac.init(key) />
<cfset mac.update(msgBytes) />
<cfreturn mac.doFinal() />
</cffunction>
这篇关于HMAC SHA1 ColdFusion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!