walkamile
walkamile

Reputation: 23

Python to Ruby Conversion, stuck on the equivalent

I currently have this string that hashes the password to connect to the server properly. It works fine for the hashing in python

import hmac
"password": hmac.new(user_pasw.encode(), (user_name + resp["challenge"]).encode(), "md5").hexdigest().upper()

Unfortunately, I've been unable to find the equivalent of to do the tuple without other gems being installed. Thus, im stuck. Is there any workaround for this?

Upvotes: 0

Views: 311

Answers (1)

Nikita Misharin
Nikita Misharin

Reputation: 2030

I believe this to be absolute ruby equivalent of provided python code

require 'openssl'
password = OpenSSL::HMAC.hexdigest(
  user_passw.force_encoding("UTF-8"),
  (user_name + resp["challenge"]).force_encoding("UTF-8"),
  'md5'
).upcase

{ password: password }

I'm pretty sure you can omit force_encoding, though. It should work anyway

Upvotes: 1

Related Questions