C #: base64url in accordance with RFC4648

I am looking for a (quick) standard implementation for base64url according to RFC4648 in C #.

I found HttpServerUtility.UrlTokenEncode , but it does not seem to comply with RFC4648 (UrlTokenEncode adds a number at the end that indicates the number of = signs that have been removed, see here and here ).

Example:

base64 encoding:

Convert.ToBase64String (System.Text.Encoding.ASCII.GetBytes ("AA")); // returns "QUE ="

base64url:

HttpServerUtility.UrlTokenEncode (System.Text.Encoding.ASCII.GetBytes ("AA")); // returns "QUE1", but I would expect "QUE"

+6
c # base64 url-encoding urlencode
Nov 04 '14 at 9:53 on
source share
1 answer

Based on the comments, it looks like HttpServerUtility.UrlTokenEncode doing the right thing, except for the extra character to fill in. Therefore, you should be able to:

 string customBase64 = HttpServerUtility.UrlTokenEncode(data); string rfc4648 = customBase64.Substring(0, customBase64.Length - 1); 

However, you must add unit tests to check if it really uses the alphabet RFC 4648 (and the same as RFC 4648). Somewhat surprisingly, the docs are so scarce :(

+7
Nov 04 '14 at 12:45
source share



All Articles