What is base64 encoding used for?

后端 未结 18 925
滥情空心
滥情空心 2020-11-22 09:45

I\'ve heard people talking about \"base 64 encoding\" here and there. What is it used for?

18条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 10:13

    The usage of Base64 I'm going to describe here is somewhat a hack. So if you don't like hacks, please do not go on.

    I went into trouble when I discovered that MySQL's utf8 does not support 4-byte unicode characters since it uses a 3-byte version of utf8. So what I did to support full 4-byte unicode over MySQL's utf8? Well, base64 encode strings when storing into the database and base64 decode when retrieving.

    Since base64 encoding and decoding is very fast, the above worked perfectly.

    You have the following points to take note of:

    • Base64 encoding uses 33% more storage

    • Strings stored in the database wont be human readable (You could sell that as a feature that database strings use a basic form of encryption).

    You could use the above method for any storage engine that does not support unicode.

提交回复
热议问题