問題描述
我們正在嘗試在 ColdFusion 中計算 HMAC-SHA256 摘要,并且我們正在使用 HMAC CFC,但在一種情況下,與以不同語言生成的摘要相比,它產生的摘要結果不同 - 嘗試使用相同的數據紅寶石&PHP 并得到預期的結果.我也嘗試過它所基于的 CF_HMAC 自定義標簽,并得到了相同的結果.
We are trying to calculate a HMAC-SHA256 digest in ColdFusion and we are using the HMAC CFC, but in one case it is producing a different result for the digest compared to ones generated in different languages - have tried the same data using Ruby & PHP and get the expected result. I have also tried the CF_HMAC custom tag it is based on and get the same results.
我了解到,從 CF8 encrypt()
開始支持 HMAC-SHA256,但它僅在 Enterprise 中可用(我們沒有),甚至在開發者版本中也沒有供我測試.
I understand that from CF8 encrypt()
supports HMAC-SHA256, but it's only available in Enterprise (which we don't have) and isn't even available in developer version for me to test.
所以我的問題是我可以通過從 CF 訪問 Java 來做到這一點嗎?
So my question is can I do this by accessing Java from CF?
推薦答案
這就是我最終做的:
secret = createObject('java', 'javax.crypto.spec.SecretKeySpec' ).Init(my_key.GetBytes(), 'HmacSHA256');
mac = createObject('java', "javax.crypto.Mac");
mac = mac.getInstance("HmacSHA256");
mac.init(secret);
digest = mac.doFinal(my_data.GetBytes());
這將為您提供字節數組,然后您可以將其轉換為字符串.
This gives you the byte array, which you can then convert to a string.
這篇關于使用 Java 在 ColdFusion 中計算 HMAC-SHA256 摘要的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!