当前位置:首页 > 操作系统 > MacOs

像这样的php函数,如何在Rails中使用hash_hmac使用sha256加密数据

我需要将此php函数转换为Rails.它用于加密我们提供的带有特殊密钥的数据.该函数的输出应与ruby函数匹配.请帮忙.

<code>public static function genHash($secret, $data) {
    $ourhash = hash_hmac('sha256', utf8_decode($data), utf8_decode($secret), FALSE);
    return $Hmac;
}
</code>

解决方法:

<code>require 'openssl'

def genHash(secret, data)
  OpenSSL::HMAC.hexdigest('sha256', secret, data)
end
</code>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐