 <p>My solution is fastest and easiest.</p> <pre><code>public class MyBase64 { private final static char[] ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray(); private static int[] toInt = new int[128]; static { for(int i=0; i&lt; ALPHABET.length; i++){ toInt[ALPHABET[i]]= i; } } /** * Translates the specified byte array into Base64 string. * * @param buf the byte array (not null) * @return the translated Base64 string (not null) */ public static String encode(byte[] buf){ int size = buf.length; char[] ar = new char[((size + 2) / 3) * 4]; int a = 0; int i=0; while(i &lt; size){ byte b0 = buf[i++]; byte b1 = (i &lt; size) ? buf[i++] : 0; byte b2 = (i &lt; size) ? buf[i++] : 0; int mask = 0x3F; ar[a++] = ALPHABET[(b0 &gt;&gt; 2) &amp; mask]; ar[a++] = ALPHABET[((b0 &lt;&lt; 4) | ((b1 &amp; 0xFF) &gt;&gt; 4)) &amp; mask]; ar[a++] = ALPHABET[((b1 &lt;&lt; 2) | ((b2 &amp; 0xFF) &gt;&gt; 6)) &amp; mask]; ar[a++] = ALPHABET[b2 &amp; mask]; } switch(size % 3){ case 1: ar[--a] = '='; case 2: ar[--a] = '='; } return new String(ar); } /** * Translates the specified Base64 string into a byte array. * * @param s the Base64 string (not null) * @return the byte array (not null) */ public static byte[] decode(String s){ int delta = s.endsWith( "==" ) ? 2 : s.endsWith( "=" ) ? 1 : 0; byte[] buffer = new byte[s.length()*3/4 - delta]; int mask = 0xFF; int index = 0; for(int i=0; i&lt; s.length(); i+=4){ int c0 = toInt[s.charAt( i )]; int c1 = toInt[s.charAt( i + 1)]; buffer[index++]= (byte)(((c0 &lt;&lt; 2) | (c1 &gt;&gt; 4)) &amp; mask); if(index &gt;= buffer.length){ return buffer; } int c2 = toInt[s.charAt( i + 2)]; buffer[index++]= (byte)(((c1 &lt;&lt; 4) | (c2 &gt;&gt; 2)) &amp; mask); if(index &gt;= buffer.length){ return buffer; } int c3 = toInt[s.charAt( i + 3 )]; buffer[index++]= (byte)(((c2 &lt;&lt; 6) | c3) &amp; mask); } return buffer; } } </code></pre>