Calculate HMAC-SHA256 digest in ColdFusion using Java(使用 Java 在 ColdFusion 中计算 HMAC-SHA256 摘要)
问题描述
我们正在尝试在 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 摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Java 在 ColdFusion 中计算 HMAC-SHA256 摘要
基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
