4

I tried the equivalent ruby code for the following PHP code.

PHP code:

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

Tried Ruby code:

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

This throws ArgumentError: wrong number of arguments (1 for 0) error. Can anybody help me with the correct equivalent ruby code.

Sam
  • 5,040
  • 12
  • 43
  • 95

1 Answers1

3

You need to concatenate your post_data and secretkey values in the same way that you're doing using the . operator in PHP, so that you're only passing a single string to the MD5 digest function.

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}")
Mark Baker
  • 209,507
  • 32
  • 346
  • 385