I have the C# code:
byte[] bytes = new UnicodeEncoding().GetBytes(input);
return Convert.ToBase64String(new SHA256Managed().ComputeHash(bytes));
that encodes a string to an SHA2 hash, which is then base 64 encoded. I need to convert this into Ruby.
I tried several ways. This is one of them:
hash = Digest::SHA256.digest(val.encode('utf-8'))
encoded = Base64.urlsafe_encode64(hash)
My code all produce the same result that doesn't match. I cannot get them to work. Any help on converting this would be appreciated.
Update
After some messing around I was able to get it working with a hard coded array, the issue is that the C# code adds a 0 after every element in the array. Here is the working ruby code (with the hard coded array):
Digest::SHA256.base64digest([99,0,104,0,97,0,100,0].pack('C*').force_encoding('utf-16'))
I suppose I could iterate through the array but that seems unnecessary.