What is the difference between Convert.ToBase64String(byte[]) and HttpServerUtility.UrlTokenEncode(byte[])?

后端 未结 2 2001
刺人心
刺人心 2021-02-20 08:00

I\'m trying to remove a dependence on System.Web.dll from a Web API project, but have stumbled on a call to HttpServerUtility.UrlTokenEncode(byte[] input) (and its

2条回答
  •  攒了一身酷
    2021-02-20 08:18

    I took DGibbs on their word and Used the Source. It turns out the following happens in the HttpServerUtility methods:

    Encoding to Base64

    1. Use System.Convert to convert the input to Base64.

    2. Replace + by - and / by _. Example: Foo+bar/=== becomes Foo-bar_===.

    3. Replace any number of = at the end of the string, with an integer denoting how many they were. Example: Foo-bar_=== becomes Foo-bar_3.

    Decoding from Base64

    1. Replace the digit at the end of the string by the same number of = signs. Example: Foo-bar_3 becomes Foo-bar_===.

    2. Replace - by + and _ by /. Example: Foo-bar_=== becomes Foo+bar/===.

    3. Use System.Convert to decode the preprocessed input from Base64.

提交回复
热议问题