C#: base64url according to RFC4648

后端 未结 1 1302
醉话见心
醉话见心 2020-12-10 16:11

I\'m looking for a (fast) standard implementation for base64url according to RFC4648 in C#.

I found HttpServerUtility.UrlTokenEncode but it looks like this doesn\'t

相关标签:
1条回答
  • 2020-12-10 16:34

    Based on the comments, it sounds like System.Web.HttpServerUtility.UrlTokenEncode does the right thing except for the extra character for padding. So you should be able to do:

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

    However, you should add unit tests to check that it really does use the RFC 4648 alphabet (and in the same way as RFC 4648). It's somewhat surprising that the docs are so sparse :(

    0 讨论(0)
提交回复
热议问题