Is it ok to remove the equal signs from a base64 string?

前端 未结 6 1130
眼角桃花
眼角桃花 2021-02-02 10:05

I have a string that I\'m encoding into base64 to conserve space. Is it a big deal if I remove the equal sign at the end? Would this significantly decrease entropy? What can I d

6条回答
  •  悲哀的现实
    2021-02-02 10:33

    Every 3 bytes you need to encode as Base64 are converted to 4 ASCII characters and the '=' character is used to pad the result so that there are always a multiple of 4 encoded characters. If you have an exact multiple of 3 bytes then you will get no equal sign. One spare byte means you get two '=' characters at the end. Two spare bytes means you get one '=' character at the end. depending on how you decode the string it may or may not see this as a valid string. With the example string you have, it doesn't decode, but some simple strings I've tried do decode.

    You can read this page for a better understanding of base64 strings and encoding/decoding.

    http://www.nczonline.net/blog/2009/12/08/computer-science-in-javascript-base64-encoding/

    There are free online encoder/decoders that you can use to check your output string

提交回复
热议问题