kristian nissen
kristian nissen

Reputation: 2907

convert php to ruby

I changed the Ruby snippet and now it works, I had forgotten to add the md5 part int he previous post, sorry. Afterwards I retested the PHP snippet as well, and both outputs are the same now.

Here is what I have so far:

PHP:

"Inx ".base64_encode('Jon').' '.base64_encode(pack( 'H*' , md5($message."werty")))

Ruby:

md5 = Digest::MD5.digest(msg +"werty")
auth = "Inx " + Base64.b64encode('Jon').strip() + " " + Base64.b64encode(md5).strip()

The output is:

PHP:

Inx Sm9u FL6ZQ1EAMcVDpUhGQ9kxjg==

Ruby:

Inx Sm9u FL6ZQ1EAMcVDpUhGQ9kxjg==

and this is the message used:

<?xml version="1.0" encoding="UTF-8"?> <push><application>Jon</application><service><![CDATA[test-2]]></service><service-provider>Absolute</service-provider><session-id>jbg01</session-id><trigger>bulk link</trigger><sms-text url="http://example.com" url-tag="xxx"><![CDATA[Hello world]]></sms-text><recipient>555555</recipient><from>5555</from></push>

I have changed some of the sensitive info from the xml so it's not quite the same as the string used in the PHP string.

Upvotes: 0

Views: 439

Answers (1)

mykhal
mykhal

Reputation: 19924

require "digest/md5"
Digest::MD5.digest(string)

produce the binary MD5 digest (16 bytes) directly, you don't need to pack

Upvotes: 1

Related Questions