public static String bytesToBase64(byte[] bytes) {
		StringBuffer sb = new StringBuffer();
		int len = bytes.length;
		int i = 0;
		int b1, b2, b3;

		while (i < len) {
			b1 = bytes[i++] & 0xff;
			if (i == len) {
				sb.append(BASE64_ENCODE_CHARS[b1 >>> 2]);
				sb.append(BASE64_ENCODE_CHARS[(b1 & 0x3) << 4]);
				sb.append("==");
				break;
			}
			b2 = bytes[i++] & 0xff;
			if (i == len) {
				sb.append(BASE64_ENCODE_CHARS[b1 >>> 2]);
				sb.append(BASE64_ENCODE_CHARS[((b1 & 0x03) << 4)
						| ((b2 & 0xf0) >>> 4)]);
				sb.append(BASE64_ENCODE_CHARS[(b2 & 0x0f) << 2]);
				sb.append("=");
				break;
			}
			b3 = bytes[i++] & 0xff;
			sb.append(BASE64_ENCODE_CHARS[b1 >>> 2]);
			sb.append(BASE64_ENCODE_CHARS[((b1 & 0x03) << 4)
					| ((b2 & 0xf0) >>> 4)]);
			sb.append(BASE64_ENCODE_CHARS[((b2 & 0x0f) << 2)
					| ((b3 & 0xc0) >>> 6)]);
			sb.append(BASE64_ENCODE_CHARS[b3 & 0x3f]);
		}
		return sb.toString();
	}