What is the advantage of using Base64 encoding?

后端 未结 8 1537
长情又很酷
长情又很酷 2020-12-13 13:18

What is the advantage of using Base64 encode?

I would like to understand it better. Do I really need it? Can\'t I simply use pure strings?

I heard that the e

相关标签:
8条回答
  • 2020-12-13 13:46

    Originally some protocols only allowed 7 bit, and sometimes only 6 bit, data.

    Base64 allows one to encode 8 bit data into 6 bits for transmission on those types of links.

    Email is an example of this.

    0 讨论(0)
  • 2020-12-13 13:49
    <img alt="Embedded Image" 
      src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />
    

    This code will show encoded image, but no one can link to this image from another website and use your traffic.

    Base64 decode

    0 讨论(0)
  • 2020-12-13 13:55

    I use it for passing around files that tend to get chewed up by email programs because they look like text files (e.g. HL7 transcripts for replay).

    0 讨论(0)
  • 2020-12-13 14:02

    The advantages of Base64 encode, like somebody said, are available to transmit data from binary, into (most commonly) ASCII characters. Due to the likeliness that the receiving end can handle ASCII, it makes it a nice way to transfer binary data, via a text stream.

    If your situation can handle native binary data, that will most likely yield better results, in terms of speed and such, but if not, Base64 is most likely the way to go. JSON is a great example of when you would benefit from something like this, or when it needs to be stored in a text field somewhere. Give us some more details and we can provide a better tailored answer.

    0 讨论(0)
  • 2020-12-13 14:06

    Whether or not to use it depends on what you're using it for.

    I've used it mostly for encoding binary data to pass through a mechanism that has really been created for text files. For example - when passing a digital certificate request around or retrieving the finished digital certificate -- in those cases, it's often very convenient to pass the binary data as Base 64 via a text field on a web form.

    I probably wouldn't use it if you have something that is already text and you just want to pass it somewhere.

    0 讨论(0)
  • 2020-12-13 14:09

    One application is to transfer binary data in contexts where only characters are allowed. E.g. in XML documents/transfers. XML-RPC is an example of this.

    0 讨论(0)
提交回复
热议问题