How to convert string to base64 byte array, would this be valid?

后端 未结 5 2030
温柔的废话
温柔的废话 2021-02-03 20:20

I\'m trying to write a function that converts a string to a base64 byte array. I\'ve tried with this approach:

public byte[] stringToBase64ByteArray(String input         


        
5条回答
  •  一生所求
    2021-02-03 21:00

    Looks okay, although the approach is strange. But use Encoding.ASCII.GetBytes() to convert the base64 string to byte[]. Base64 encoding only contains ASCII characters. Using Unicode gets you an extra 0 byte for each character.

提交回复
热议问题