I am trying to replicate Convert.ToBase64String () behavior in Ruby.
Here is my C # code:
var sha1 = new SHA1CryptoServiceProvider();
var passwordBytes = Encoding.UTF8.GetBytes("password");
var passwordHash = sha1.ComputeHash(passwordBytes);
return Convert.ToBase64String(passwordHash);
When I try to do the same in Ruby, I get a different base64 string for the same sha1 hash:
require 'digest/sha1'
require 'base64'
sha1 = Digest::SHA1.hexdigest('password')
base64 = Base64.strict_encode64(sha1)
I checked in the debugger that the C # byte array passwordBytesmatches the value sha1in the Ruby example. Is there a special way that I need to use Base64 in Ruby to get the same line as C # code?
source
share