HMAC SHA256十六进制消息中的一个字符串在Erlang,怎么样? [英] HMAC SHA256 hex digest of a string in Erlang, how?

查看:298
本文介绍了HMAC SHA256十六进制消息中的一个字符串在Erlang,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与第三方实时Web消息系统进行交互,由 Pusher.com 的。现在,我不能通过API发送任何东西,除非我生成一个我的数据的 HMAC SHA256十六进制摘要。用 ruby​​ 编写的示例源代码可以尝试说明这一点:

I am trying to interact with third party real time Web messaging System created and maintained by Pusher.com. Now, i cannot send anything through the API unless i produce an HMAC SHA256 hex digest of my data. A sample source code written in ruby could try to illustrate this:


# Dependencies
# gem install ruby-hmac
#
require 'rubygems'
require 'hmac-sha2'

secret = '7ad3773142a6692b25b8'
string_to_sign = "POST\n/apps/3/channels/test_channel/events\nauth_key=278d425bdf160c739803&auth_timestamp=1272044395&auth_version=1.0&body_md5=7b3d404f5cde4a0b9b8fb4789a0098cb&name=foo"

hmac = HMAC::SHA256.hexdigest(secret, string_to_sign)

puts hmac
# >> 309fc4be20f04e53e011b00744642d3fe66c2c7c5686f35ed6cd2af6f202e445

我检查了一个href =http://www.erlang.org/doc/apps/crypto/index.html =nofollow noreferrer> erlang加密库 ,我甚至不能生成一个 SHA256十六进制摘要直接


我如何在Erlang做这件事? 帮助....



*更新*


我在这里找到了解决方案: 在erlang中的sha256加密 ,他们导致我进入 erlsha2 。但是,如何从该模块生成 SHA256 hexdigest 输出的 HMAC

I checked the erlang crypto Library and i cannot even generate a SHA256 hex digest "directly"

How do i do this whole thing in Erlang ? help....

* UPDATE *

I have found solutions here: sha256 encryption in erlang and they have led me to erlsha2. But still, how do i generate the HMAC of a SHA256 hexdigest output from this module ?

推荐答案

使用 erlsha2 ,使用以下内容获得相当于您的Ruby代码:

With erlsha2, use the following to get the equivalent of your Ruby code:

1> hmac:hexlify(hmac:hmac256(<<"7ad3773142a6692b25b8">>, <<"POST\n/apps/3/channels/test_channel/events\nauth_key=278d425bdf160c739803&auth_timestamp=1272044395&auth_version=1.0&body_md5=7b3d404f5cde4a0b9b8fb4789a0098cb&name=foo">>)).
"309FC4BE20F04E53E011B00744642D3FE66C2C7C5686F35ED6CD2AF6F202E445"

这篇关于HMAC SHA256十六进制消息中的一个字符串在Erlang,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆