简体   繁体   English

PHP MD5 Key的等效ruby代码

[英]Equivalent ruby code for PHP MD5 Key

I tried the equivalent ruby code for the following PHP code. 我尝试了以下PHP代码的等效ruby代码。

PHP code: PHP代码:

 var  $secretKey = "19535CF3D949D4EF56F8D3D4ED78C505";
 $sign=md5 ($post_data.$this->secretKey );

Tried Ruby code: 试过Ruby代码:

secretKey = "19535CF3D949D4EF56F8D3D4ED78C505"
Digest::MD5.hexdigest(post_data, secretkey)

This throws ArgumentError: wrong number of arguments (1 for 0) error. 抛出ArgumentError:错误的参数数量(1表示0)错误。 Can anybody help me with the correct equivalent ruby code. 任何人都可以帮助我使用正确的等效ruby代码。

You need to concatenate your post_data and secretkey values in the same way that you're doing using the . 您需要以与使用的方式相同的方式连接post_datasecretkey. operator in PHP, so that you're only passing a single string to the MD5 digest function. PHP中的运算符,因此您只需将单个字符串传递给MD5摘要函数。

Digest::MD5.hexdigest(post_data + secretkey)

is the simplest method, though you could also use 是最简单的方法,但你也可以使用

Digest::MD5.hexdigest(post_data << secretkey) 

or 要么

Digest::MD5.hexdigest("#{post_data}#{secretkey}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM