This is a C# code:
byte[] pb = System.Text.Encoding.UTF8.GetBytes(policy.ToString());
// Encode those UTF-8 bytes using Base64
string policyB = Convert.ToBase64String(pb);
// Sign the policy with your Secret Key using HMAC SHA-1.
System.Security.Cryptography.HMACSHA1 hmac = new System.Security.Cryptography.HMACSHA1();
hmac.Key = System.Text.Encoding.UTF8.GetBytes(secretKey);
byte[] signb = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(policyB));
string signature = Convert.ToBase64String(signb);
How to do the same in Ruby on rails? More specifically I need to know functions to get bytes from string and base64 encode them and calculate hmac hash.