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.

11149 questions
1297
votes
12 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
  • 51,492
  • 15
  • 48
  • 55
1209
votes
8 answers

How can I 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 hexadecimal, binary or ASCII data. For example: var cipher = crypto.createCipheriv('des-ede3-cbc', encryption_key, iv); var ciph =…
murvinlai
  • 48,919
  • 52
  • 129
  • 177
1205
votes
33 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
  • 18,800
  • 11
  • 41
  • 45
1110
votes
14 answers

How to display Base64 images in HTML

I'm having trouble displaying a Base64 image inline. How can I do it? Display Image
Christopher
  • 12,057
  • 9
  • 31
  • 37
1013
votes
19 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
  • 43,245
  • 41
  • 111
  • 153
763
votes
19 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
  • 34,704
  • 19
  • 73
  • 95
726
votes
20 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?
coderslay
  • 13,960
  • 31
  • 73
  • 121
706
votes
15 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
  • 85
  • 340
  • 366
575
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,593
  • 6
  • 24
  • 24
537
votes
21 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,461
  • 5
  • 25
  • 20
484
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
  • 26,147
  • 8
  • 50
  • 69
473
votes
10 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
  • 27,666
  • 26
  • 83
  • 129
431
votes
13 answers

Why do we use Base64?

Wikipedia says Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remains intact without…
Lazer
  • 90,700
  • 113
  • 281
  • 364
396
votes
21 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
  • 36,107
  • 79
  • 222
  • 382
379
votes
1 answer

NodeJS: How to decode base64 encoded string back to binary?

I was implementing password hashing with salt, so I generated salt as binary, hashed the password, base64 encoded the password and salt then stored them into database. Now when I am checking password, I am supposed to decode the salt back into…
Xavier_Ex
  • 8,432
  • 11
  • 39
  • 55
1
2 3
99 100