Skip to content Skip to sidebar Skip to footer

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()

Solution 1:

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

Post a Comment for "Python To Ruby Conversion, Stuck On The Equivalent"