.NET: Why is there no 64 base in .GetEncodings () encoding?

I have a function that can decode an array of bytes into a string of characters using the specified encoding.

Example:

Function Decode(ByVal bytes() As Byte, ByVal codePage As String) As String Dim enc As Text.Encoding = Text.Encoding.GetEncoding(codePage) Return enc.GetString(bytes) End Function 

If I want to include base64 in this, I should do something like this:

 Function Decode(ByVal bytes() As Byte, ByVal codePage As String) As String If String.Compare(codePage, "base64", True) = 0 Then Return Convert.ToBase64String(bytes) Else Dim enc As Text.Encoding = Text.Encoding.GetEncoding(codePage) Return enc.GetString(bytes) End If End Function 

Why is base64 handled in a special way in .NET?

+4
source share
2 answers

This is actually not the same thing:

  • Encodings are ways to represent arbitrary text in binary form.
  • Base64 is a way to represent arbitrary binary data in text form.

Normally you would not use them in the same circumstances. You should use encoding when the "real" data is text, and base64 when the "real" data is binary.

Of course, you can implement the encoding for base64, but personally I do not think this is a good idea.

+22
source

In System.Convert

-1
source

All Articles