Java 代码 ruby

Java code to ruby

我想将其转换为 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)