Questions tagged [base64]

Base64 is a set of encoding schemes that represent binary data in an ASCII string format.

Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding.

Base64 uses characters 0 to 9, A to Z and a to z to represent digits of 64-decimal numbers. The last two required digits differ between schemas. For instance, MIME (RFC 2045) uses + and / , XML names tokens use - and ., XML identifiers use _ and : and regular expressions use ! and -.

When encoding in Base64 text, 3 bytes are typically encoded into 4 characters. To encode arbitrary lengths, the padding character (=) is used. = at the end of encoded sequence means that only two bytes and == means that only one byte is encoded by the last 4 character group.

Characters outside the discussed alphabet are normally forbidden, except in MIME where they are discarded.

Base64 encoding schemes are commonly used when there is a need to encode binary data that need to be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remain intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, or to store binary data in textual formats such as XML or JSON.

Useful online tools

They work without enabled JavaScript too.

9990 questions
1052
votes
10 answers

How do I encode and decode a base64 string?

How do I return a base64 encoded string given a string? How do I decode a base64 encoded string into a string?
Kevin Driedger
  • 44,076
  • 15
  • 45
  • 55
965
votes
7 answers

How to do Base64 encoding in node.js?

Does node.js have built-in base64 encoding yet? The reason why I ask this is that final() from crypto can only output hex, binary or ascii data. For example: var cipher = crypto.createCipheriv('des-ede3-cbc', encryption_key, iv); var ciph =…
murvinlai
  • 43,517
  • 50
  • 120
  • 169
939
votes
28 answers

How can you encode a string to Base64 in JavaScript?

I have a PHP script that can encode a PNG image to a Base64 string. I'd like to do the same thing using JavaScript. I know how to open files, but I'm not sure how to do the encoding. I'm not used to working with binary data.
username
  • 15,721
  • 11
  • 37
  • 44
862
votes
18 answers

What is base 64 encoding used for?

I've heard people talking about "base 64 encoding" here and there. What is it used for?
MrDatabase
  • 39,447
  • 40
  • 105
  • 151
795
votes
12 answers

How to display Base64 images in HTML?

I'm having trouble displaying a Base64 image inline. Can someone point me in the right direction? Display Image
Christopher
  • 8,739
  • 8
  • 28
  • 37
668
votes
18 answers

Binary Data in JSON String. Something better than Base64

The JSON format natively doesn't support binary data. The binary data has to be escaped so that it can be placed into a string element (i.e. zero or more Unicode chars in double quotes using backslash escapes) in JSON. An obvious method to escape…
dmeister
  • 32,008
  • 19
  • 67
  • 92
579
votes
16 answers

How can I convert an image into Base64 string using JavaScript?

I need to convert my image to a Base64 string so that I can send my image to a server. Is there any JavaScript file for this? Else, how can I convert it?
Coder_sLaY
  • 12,295
  • 29
  • 71
  • 117
567
votes
3 answers

Embedding Base64 Images

Purely out of curiosity, which browsers does Base64 image embedding work in? What I'm referring to is this. I realize it's not usually a good solution for most things, as it increases the page size quite a bit - I'm just curious. Some…
S Pangborn
  • 12,153
  • 6
  • 22
  • 24
530
votes
12 answers

Creating a BLOB from a Base64 string in JavaScript

I have Base64-encoded binary data in a string: const contentType = 'image/png'; const b64Data = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; I would like to create a blob:…
Jeremy
  • 1
  • 77
  • 324
  • 346
501
votes
20 answers

Decode Base64 data in Java

I have an image that is Base64 encoded. What is the best way to decode that in Java? Hopefully using only the libraries included with Sun Java 6.
Ryan P
  • 6,091
  • 5
  • 22
  • 19
478
votes
12 answers

Is embedding background image data into CSS as Base64 good or bad practice?

I was looking at the source of a greasemonkey userscript and noticed the following in their css: .even { background: #fff…
Dimitar Christoff
  • 25,905
  • 8
  • 47
  • 66
368
votes
18 answers

How to Resize a Bitmap in Android?

I have a bitmap taken of a Base64 String from my remote database, (encodedImage is the string representing the image with Base64): profileImage = (ImageView)findViewById(R.id.profileImage); byte[] imageAsBytes=null; try { imageAsBytes =…
NullPointerException
  • 32,153
  • 66
  • 194
  • 346
364
votes
9 answers

Why does a base64 encoded string have an = sign at the end

I know what base64 encoding is and how to calculate base64 encoding in C#, however I have seen several times that when I convert a string into base64, there is an = at the end. A few questions came up: Does a base64 string always end with =? Why…
santosh singh
  • 25,036
  • 23
  • 75
  • 121
347
votes
8 answers

Get image data URL in JavaScript?

I have a regular HTML page with some images (just regular HTML tags). I'd like to get their content, base64 encoded preferably, without the need to redownload the image (ie. it's already loaded by the browser, so now I want the content). I'd…
Detariael
  • 3,862
  • 4
  • 17
  • 10
344
votes
19 answers

Encoding as Base64 in Java

I need to encode some data in the Base64 encoding in Java. How do I do that? What is the name of the class that provides a Base64 encoder? I tried to use the sun.misc.BASE64Encoder class, without success. I have the following line of Java 7…
Jury A
  • 16,048
  • 23
  • 65
  • 85
1
2 3
99 100