0

Is there a way to perform Base64Url conversion of byte array to a pre-allocated char array like ToBase64CharArray does?

I need to reuse the char buffer instead of getting new string every time, so Base64UrlEncoder is not suitable.

jps
  • 20,041
  • 15
  • 75
  • 79
mrbus2007
  • 197
  • 7
  • so basically `ToBase64CharArray` is ok, but you need Base64Url encoding instead of Base64 encoding. Is that correct? – jps Nov 21 '20 at 17:32
  • @jps Yes exactly. I could use ToBase64CharArray and replace the / + characters manually, but maybe there is an existing method? – mrbus2007 Nov 21 '20 at 17:36
  • The Azure SDK has [this](https://learn.microsoft.com/en-us/dotnet/api/microsoft.identitymodel.tokens.base64urlencoder?view=azure-dotnet) – Mark Benningfield Nov 21 '20 at 17:54
  • ASP.Net has [this](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.webutilities.webencoders.base64urlencode?view=aspnetcore-5.0) – Mark Benningfield Nov 21 '20 at 17:56
  • @MarkBenningfield Looks like a solution. I will check it. Thank you – mrbus2007 Nov 22 '20 at 16:47
  • @MarkBenningfield WebEncoders.Base64UrlEncode is suitable, but unfortunately there is no corresponding method to _decode_ from pre-allocated char array to pre-allocated byte array. Please post me if you know such method, thanks – mrbus2007 Nov 25 '20 at 23:54

0 Answers0