/// <summary> /// Decodes the string /// </summary> /// <param name="str"></param> /// <returns></returns> public static string FromBase64UrlEncoded(this string str) { var base64String = HttpUtility.UrlDecode(str); var encodedIdBytes = Convert.FromBase64String(base64String); var id = Encoding.UTF8.GetString(encodedIdBytes); return id; }and also
/// <summary> /// Encodes the string /// </summary> /// <param name="str"></param> /// <param name="trimBeforeHashing"></param> /// <returns></returns> public static string ToBase64UrlEncoded(this string str, bool trimBeforeHashing = false) { if (trimBeforeHashing && !String.IsNullOrEmpty(str)) { str = str.Trim(); } var idBytes = Encoding.UTF8.GetBytes(str); var idBase64String = Convert.ToBase64String(idBytes); var idUrlString = HttpUtility.UrlEncode(idBase64String); return idUrlString; }The result of the ToBase64UrlEncoded is what we name, for example, categoryHash and what we're sending in our API calls.
idUrlString = "Q0%2fDkUFDICAgICA%3d"
. Do you see what make it wrong? Also I noticed that it produced 11 bytes while for all other strings it correctly produced 10 bytes (our columns being 10 characters in length). May be we can not use UTF8 here?