如何在Ruby中使用HMAC模块创建MD5哈希? [英] How to create MD5 hash with HMAC module in Ruby?

查看:87
本文介绍了如何在Ruby中使用HMAC模块创建MD5哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google + Bing并没有给出应该是一个简单问题的答案:

Using Google + Bing didn't yield an answer to what should be a simple question:

您应该如何在Ruby中使用HMAC模块来创建带有MD5(使用秘密)的HMAC?

How are you supposed to use the HMAC module in Ruby to create a HMAC with MD5 (that uses a secret)?

HMAC文档似乎太薄了.

The HMAC docs seem awfully thin.

谢谢!

推荐答案

应安装以下gem:'ruby-hmac'

The following gem should be installed: 'ruby-hmac'

$ irb
>> require 'hmac-md5'
=> true
>> HMAC::MD5.new("abc").digest
=> "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~"
>> HMAC::MD5.new("abc").hexdigest
=> "d41d8cd98f00b204e9800998ecf8427e"
>> 

这篇关于如何在Ruby中使用HMAC模块创建MD5哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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