public static byte[] toArray (String s) {
		
		// remove all non-Base64 characters from string.
		int strSize = s.length();
		for (int n = 0; n < strSize; n++) {
			char ch = s.charAt (n);
			if (charset.indexOf (ch) == -1) {
				s = s.substring (0, n) + s.substring (n+1);
				strSize--;
				n--;
			}
		}
		// check length of input string.
		if (strSize == 0 || (strSize % 4) != 0)
			return null;

		// compute padding bytes
		int padding = 0;
		if (s.charAt(strSize-1) == '=') padding++;
		if (s.charAt(strSize-2) == '=') padding++;
		
		// compute size of resulting byte array
		int size = 3 * strSize / 4 - padding;
		byte[] res = new byte [size];
		int pos = 0;
		
		// process Base64 string
		for (int n = 0; n < strSize; n += 4) {
			// reconstruct three-byte integer
			int val = charset.indexOf (s.charAt(n));
			val = (val << 6) |  charset.indexOf (s.charAt(n+1));
			val = (val << 6) | (charset.indexOf (s.charAt(n+2)) & 0x3F);
			val = (val << 6) | (charset.indexOf (s.charAt(n+3)) & 0x3F);
			// copy to array
			res[pos++] = (byte) ((val >> 16) & 0xFF);
			if (pos < size) res[pos++] = (byte) ((val >> 8) & 0xFF);
			if (pos < size) res[pos++] = (byte) ( val       & 0xFF);
		}
		// return byte array
		return res;
	}