code: public static byte[] decode(String in) {
  
  		in = in.replaceAll("\\r|\\n","");
  		if(in.length() % 4 != 0) {
  			throw new IllegalArgumentException("The length of the input string must be a multiple of four.");
  		}
  
  		if(!in.matches("^[A-Za-z0-9+/]*[=]{0,3}$")) {
  			throw new IllegalArgumentException("The argument contains illegal characters.");
  		}
  
  		byte[] out = new byte[(in.length()*3)/4];
  
  		char[] input = in.toCharArray();
  
  		int outi = 0;
  		int b1, b2, b3, b4;
  		for(int i = 0; i < input.length; i+=4) {
  			b1 = map.get(input[i]) - 1;
  			b2 = map.get(input[i+1]) - 1;
  			b3 = map.get(input[i+2]) - 1;
  			b4 = map.get(input[i+3]) - 1;
  			out[outi++] = (byte)(b1 << 2 | b2 >>> 4);
  			out[outi++] = (byte)((b2 & 0x0F) << 4 | b3 >>> 2);
  			out[outi++] = (byte)((b3 & 0x03) << 6 | (b4 & 0x3F));
  		}
  
  		if(in.endsWith("=")) {
  			byte[] trimmed = new byte[out.length - (in.length() - in.indexOf("="))];
  			System.arraycopy(out, 0, trimmed, 0, trimmed.length);
  			return trimmed;
  		}
  
  		return out;
  
  	}
docs: Decode a base64 encoded string to a byte array.
  
  @param in A string representing a base64 encoding.
  @return The decoded byte array.