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 摘要


- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01