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
171
votes
11 answers

converting a base 64 string to an image and saving it

Here is my code: protected void SaveMyImage_Click(object sender, EventArgs e) { string imageUrl = Hidden1.Value; string saveLocation = Server.MapPath("~/PictureUploads/whatever2.png") ; HttpWebRequest…
anthonypliu
  • 12,179
  • 28
  • 92
  • 154
169
votes
4 answers

Converting file into Base64String and back again

The title says it all: I read in a tar.gz archive like so break the file into an array of bytes Convert those bytes into a Base64 string Convert that Base64 string back into an array of bytes Write those bytes back into a new tar.gz file I can…
darkpbj
  • 2,892
  • 4
  • 22
  • 32
166
votes
7 answers

Android Bitmap to Base64 String

How do I convert a large Bitmap (photo taken with the phone's camera) to a Base64 String?
Pankaj Singh
  • 2,241
  • 2
  • 16
  • 16
166
votes
9 answers

How to convert Base64 String to javascript file object like as from file input form?

I want to convert Base64String extracted from file(ex: "AAAAA....~") to a javascript file object. The javascript file object what I mean is like this code: HTML: JS: $('#selectFile').on('change', function(e)…
Dayamre
  • 1,907
  • 2
  • 13
  • 10
165
votes
17 answers

How can I encode a string to Base64 in Swift?

I want to convert a string to Base64. I found answers in several places, but it does not work anymore in Swift. I am using Xcode 6.2. I believe the answer might be work in previous Xcode versions and not Xcode 6.2. Could someone please guide me to…
Ankahathara
  • 2,866
  • 2
  • 20
  • 26
165
votes
8 answers

How to base64 encode image in linux bash / shell

I'm trying to base64 encode an image in a shell script and put it into variable: test="$(printf DSC_0251.JPG | base64)" echo $test RFNDXzAyNTEuSlBH I've also tried something like this: test=\`echo -ne DSC_0251.JPG | base64\` but still with no…
dash00
  • 1,763
  • 2
  • 11
  • 4
163
votes
10 answers

How to achieve Base64 URL safe encoding in C#?

I want to achieve Base64 URL safe encoding in C#. In Java, we have the common Codec library which gives me an URL safe encoded string. How can I achieve the same using C#? byte[] toEncodeAsBytes =…
Vishvesh Phadnis
  • 2,448
  • 5
  • 19
  • 35
161
votes
20 answers

How do I base64 encode (decode) in C?

I have binary data in an unsigned char variable. I need to convert them to PEM base64 in c. I looked in openssl library but i could not find any function. Does any body have any idea?
Granit
160
votes
18 answers

How can I convert an image into a Base64 string?

What is the code to transform an image (maximum of 200 KB) into a Base64 String? I need to know how to do it with Android, because I have to add the functionality to upload images to a remote server in my main app, putting them into a row of the…
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
159
votes
12 answers

Convert an image (selected by path) to base64 string

How do you convert an image from a path on the user's computer to a base64 string in C#? For example, I have the path to the image (in the format C:/image/1.gif) and would like to have a data URI like…
vaj90
  • 1,803
  • 3
  • 17
  • 17
157
votes
7 answers

Using JavaScript to display a Blob

I am retrieving a Blob image from a database, and I'd like to be able to view that image using JavaScript. The following code produces a broken image icon on the page: var image = document.createElement('image'); image.src =…
GAgnew
  • 3,847
  • 3
  • 26
  • 28
152
votes
13 answers

The input is not a valid Base-64 string as it contains a non-base 64 character

I have a REST service that reads a file and sends it to another console application after converting it to Byte array and then to Base64 string. This part works, but when the same stream is received at the application, it gets manipulated and is no…
Rohit Verma
  • 1,669
  • 2
  • 11
  • 10
151
votes
11 answers

Base64 encoding in SQL Server 2005 T-SQL

I'd like to write a T-SQL query where I encode a string as a Base64 string. Surprisingly, I can't find any native T-SQL functions for doing Base64 encoding. Does a native function exist? If not, what's the best way to do Base64 encoding in T-SQL?
Jacob
  • 77,566
  • 24
  • 149
  • 228
151
votes
15 answers

How to convert uint8 Array to base64 Encoded String?

I got a webSocket comunication, I recieve base64 encoded string, convert it to uint8 and work on it, but now I need to send back, I got the uint8 array, and need to convert it to base64 string, so I can send it. How can I make this convertion?
Caio Keto
  • 1,919
  • 4
  • 20
  • 30
147
votes
5 answers

Can we convert a byte array into an InputStream in Java?

Can we convert a byte array into an InputStream in Java? I have been looking on the internet but couldn't find it. I have a method that has an InputStream as argument. The InputStream cph I have is base64 encoded so I had to decode it…
rover12
  • 2,806
  • 7
  • 27
  • 28