public String
toString(byte [] b) {
	ByteArrayOutputStream os = new ByteArrayOutputStream();

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

		int blocklen = 5;
		for (int j = 0; j < 5; j++) {
			if ((i * 5 + j) < b.length)
				s[j] = (short) (b[i * 5 + j] & 0xFF);
			else {
				s[j] = 0;
				blocklen--;
			}
		}
		int padlen = blockLenToPadding(blocklen);

		// convert the 5 byte block into 8 characters (values 0-31).

		// upper 5 bits from first byte
		t[0] = (byte) ((s[0] >> 3) & 0x1F);
		// lower 3 bits from 1st byte, upper 2 bits from 2nd.
		t[1] = (byte) (((s[0] & 0x07) << 2) | ((s[1] >> 6) & 0x03));
		// bits 5-1 from 2nd.
		t[2] = (byte) ((s[1] >> 1) & 0x1F);
		// lower 1 bit from 2nd, upper 4 from 3rd
		t[3] = (byte) (((s[1] & 0x01) << 4) | ((s[2] >> 4) & 0x0F));
		// lower 4 from 3rd, upper 1 from 4th.
		t[4] = (byte) (((s[2] & 0x0F) << 1) | ((s[3] >> 7) & 0x01));
		// bits 6-2 from 4th
		t[5] = (byte) ((s[3] >> 2) & 0x1F);
		// lower 2 from 4th, upper 3 from 5th;
		t[6] = (byte) (((s[3] & 0x03) << 3) | ((s[4] >> 5) & 0x07));
		// lower 5 from 5th;
		t[7] = (byte) (s[4] & 0x1F);

		// write out the actual characters.
		for (int j = 0; j < t.length - padlen; j++) {
			char c = alphabet.charAt(t[j]);
			if (lowercase)
				c = Character.toLowerCase(c);
			os.write(c);
		}

		// write out the padding (if any)
		if (padding) {
			for (int j = t.length - padlen; j < t.length; j++)
				os.write('=');
		}
	}

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

@param b An array containing binary data
@return A String containing the encoded data
src/main/java/core/org/xbill/DNS/utils/base32.java