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

后端 未结 5 2032
温柔的废话
温柔的废话 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:06

    Representing a string as a blob represented as a string is odd... any reason you can't just use the string directly?

    The string is always unicode; it is the encoded bytes that change. Since base-64 is always <128, using unicode in the last part seems overkill (unless that is what the wire-format demands). Personally, I'd use UTF8 or ASCII for the last GetBytes so that each base-64 character only takes one byte.

提交回复
热议问题