Base64 : Java Glossary

go to home page B words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish by Roedy Green ©1996-2009 Canadian Mind Products
index page for letter ⇒ punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
Base64
A way of encoding 8-bit characters using only ASCII printable characters similar to UUENCODE. UUENCODE embeds a filename where BASE64 does not. You will see BASE64 used in encoding digital certificates, in encoding user:password string in an Authorization: header for HTTP. The spec is described in RFC 2045.

Don’t confuse it with x-www-form-urlencoded which is handled by java.net. URLEncoder. encode/decode.

This process of converting binary data to printable characters as sometimes called armouring because it protects the data from transport systems that meddle with, ignore or act on control characters embedded in the data.

Under the Hood

BASE64 is a scheme where 3 bytes are concatenated, then split to form 4 groups of 6-bits each; and each 6-bits gets translated to an encoded printable ASCII character, via a table lookup. An encoded string is therefore longer than the original by about 1/3. The "=" character is used to pad the end out to an even multiple of four.

Base 64 armouring uses only the characters A-Z, a-z, 0-9 and +/=. This makes it suitable for encoding binary data as SQL strings, that will work no matter what the encoding. Unfortunately + / and = all have special meaning in URLs.

Implementations

I have written source code for encoding/decoding BASE64 that you can download. Sun has an undocumented method called sun.misc.BASE64Encoder. encode. There is a non-public class in Java 1.4+ called java.util.prefs.Base64. JavaMail MimeUtility. decode( bais, "Base64"); can encode and decode a number of encodings.

Learning More

will encode/decode base64, quoted-printable, 7bit, 8bit, binary and uuencode.

CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.58]
You are visitor number 51,036.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/base64.html J:\mindprod\jgloss\base64.html