public byte[]
fromString(String str) {
	ByteArrayOutputStream bs = new ByteArrayOutputStream();
	byte [] raw = str.getBytes();
	for (int i = 0; i < raw.length; i++)
	{
		char c = (char) raw[i];
		if (!Character.isWhitespace(c)) {
			c = Character.toUpperCase(c);
			bs.write((byte) c);
		}
	}

	if (padding) {
		if (bs.size() % 8 != 0)
			return null;
	} else {
		while (bs.size() % 8 != 0)
			bs.write('=');
	}

	byte [] in = bs.toByteArray();

	bs.reset();
	DataOutputStream ds = new DataOutputStream(bs);

	for (int i = 0; i < in.length / 8; i++) {
		short[] s = new short[8];
		int[] t = new int[5];

		int padlen = 8;
		for (int j = 0; j < 8; j++) {
			char c = (char) in[i * 8 + j];
			if (c == '=')
				break;
			s[j] = (short) alphabet.indexOf(in[i * 8 + j]);
			if (s[j] < 0)
				return null;
			padlen--;
		}
		int blocklen = paddingToBlockLen(padlen);
		if (blocklen < 0)
			return null;

		// all 5 bits of 1st, high 3 (of 5) of 2nd
		t[0] = (s[0] << 3) | s[1] >> 2;
		// lower 2 of 2nd, all 5 of 3rd, high 1 of 4th
		t[1] = ((s[1] & 0x03) << 6) | (s[2] << 1) | (s[3] >> 4);
		// lower 4 of 4th, high 4 of 5th
		t[2] = ((s[3] & 0x0F) << 4) | ((s[4] >> 1) & 0x0F);
		// lower 1 of 5th, all 5 of 6th, high 2 of 7th
		t[3] = (s[4] << 7) | (s[5] << 2) | (s[6] >> 3);
		// lower 3 of 7th, all of 8th
		t[4] = ((s[6] & 0x07) << 5) | s[7];

		try {
			for (int j = 0; j < blocklen; j++)
				ds.writeByte((byte) (t[j] & 0xFF));
		}
		catch (IOException e) {
		}
	}

    return bs.toByteArray();
}
Convert a base32-encoded String to binary data

@param str A String containing the encoded data
@return An array containing the binary data, or null if the string is invalid
src/main/java/core/org/xbill/DNS/utils/base32.java