gpt4 book ai didi

Java 代码到 ruby

转载 作者:行者123 更新时间:2023-12-02 11:59:58 25 4
gpt4 key购买 nike

我想将其转换为 ruby​​ 语法,但我无法理解以下代码中用于编码的方法。

String orderAmount = "250.00";
String mobile = " 7687675645";
String email = "a@abc.com" ;
String data=mobile+email+orderAmount+"INR";
javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA1");
mac.init(new javax.crypto.spec.SecretKeySpec(secret_key.getBytes(), "HmacSHA1"));
byte[] hexBytes = new org.apache.commons.codec.binary.Hex().encode(mac.doFinal(data.getBytes()));
String signature = new String(hexBytes, "UTF-8");

非常感谢您的帮助。

最佳答案

尝试this :

require 'openssl'

secret_key = 'place_your_secret_key_here'
orderAmount = '250.00'
mobile = ' 7687675645'
email = 'a@abc.com'
data = mobile + email + orderAmount + 'INR'

signature = OpenSSL::HMAC.hexdigest('SHA1', secret_key, data)

关于Java 代码到 ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47347498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com