Base64 encode using URL-safe encoding with padding removed.

    @param b bytes to decode
    @return bytes decoded
172327
def raw_urlsafe_b64encode(b):
    '''
    '''
    b = to_bytes(b)
    b = base64.urlsafe_b64encode(b)
    b = b.rstrip(b'=')  # strip padding
    return b
105525
public static String toHex(byte b) {
      StringBuilder sb = new StringBuilder();
      appendByteAsHex(sb, b);
      return sb.toString();
   }
508311
static public byte[] decode(String base16) {
        String string = base16.replaceAll("\\s", "");  // remove all white space
        int length = string.length();
        byte[] bytes = new byte[(int) Math.ceil(length / 2.0)];
        for (int i = 0; i < bytes.length; i++) {
            decodeByte(string, i, bytes);
        }
        return bytes;
    }
946016
@Nullable protected byte[] decode(@Nullable String data) {
    return data == null ? null : Base64.getUrlDecoder().decode(data);
  }
1331245
@SneakyThrows
    public static String decodeByteArrayToString(final byte[] bytes) {
        @Cleanup
        val bais = new ByteArrayInputStream(bytes);
        @Cleanup
        val baos = new ByteArrayOutputStream();
        val buf = new byte[bytes.length];
        try (val iis = new InflaterInputStream(bais)) {
            var count = iis.read(buf);
            while (count != -1) {
                baos.write(buf, 0, count);
                count = iis.read(buf);
            }
            return new String(baos.toByteArray(), StandardCharsets.UTF_8);
        } catch (final Exception e) {
            LOGGER.error("Base64 decoding failed", e);
            return null;
        }
    }
410603
private static String encodeBase64(final byte[] buffer) {
        final int l = buffer.length;
        final char[] out = new char[l << 1];
        int j = 0;
        for (int i = 0; i < l; i++) {
            out[j++] = DIGITS[(0xF0 & buffer[i]) >>> 4];
            out[j++] = DIGITS[0x0F & buffer[i]];
        }
        return String.copyValueOf(out);
    }
1278745
public static String bytesToBase64Url(byte[] bytes) {
        String result = (new String(Base64.encodeBase64(bytes), MESSAGE_ENCODING)).replace("=", "").replace("\\", "").replace('+', '-')
                .replace('/', '_');
        return result;
    }
746041
public static String encode(String content) {
		if (content == null || content.length() == 0) {
			return content;
		}
		return org.apache.commons.codec.binary.Base64.encodeBase64String(content.getBytes()).trim();

	}
955223
public static String base64Decode(String base64Str,String encoding) throws IOException{
		byte [] rawByte = base64Str.getBytes(encoding);
		return new String(SecureUtil.base64Decode(rawByte),encoding);	
	}
1256472
def b64d(b):
    

    cb = b.rstrip(b"=")  # shouldn't but there you are

    # Python's base64 functions ignore invalid characters, so we need to
    # check for them explicitly.
    if not _b64_re.match(cb):
        raise BadSyntax(cb, "base64-encoded data contains illegal characters")

    if cb == b:
        b = add_padding(b)

    return base64.urlsafe_b64decode(b)
33170
public static String encodeUrlSafe(String source, String charset) {
		return Base64Encoder.encodeUrlSafe(source, charset);
	}
679376
public static byte[] decode(String s) {

        if( s == null ){
            throw new IllegalArgumentException("Input string was null.");
        }

        byte[] inBytes;
        try {
            inBytes = s.getBytes("US-ASCII");
        }
        catch( java.io.UnsupportedEncodingException uee ) {
            inBytes = s.getBytes();
        }

        if( inBytes.length == 0 ) {
            return new byte[0];
        } else if( inBytes.length < 4 ){
            throw new IllegalArgumentException(
                    "Base64-encoded string must have at least four characters, but length specified was " + inBytes.length);
        }   // end if

        return decodeBytes(inBytes);
    }
287100
private static char b64encode(int b)
	{
		if (b >= 0 && b <= 25)
		{
			return (char) ('A' + b);
		}

		if (b >= 26 && b <= 51)
		{
			return (char) ('a' + b - 26);
		}

		if (b >= 52 && b <= 61)
		{
			return (char) ('0' + b - 52);
		}

		if (b == 62)
		{
			return '+';
		}

		if (b == 63)
		{
			return '/';
		}

		return '?';
	}
1162054
@SuppressWarnings("unchecked")
        public static <T> T decode(String base64) {
                //BASE64Decoder decoder = new BASE64Decoder();
                try {
                        //byte[]               b    = decoder.decodeBuffer(base64);
                		byte[]               b    = Base64.decode(base64);
                        ByteArrayInputStream bais = new ByteArrayInputStream(b);
                        ObjectInputStream    ois  = new ObjectInputStream(bais);
                        return (T)ois.readObject();
                } catch (IOException | ClassNotFoundException e) {
                        throw new RuntimeException(e);
                }
        }
539081
public static String encodeBase64(final byte[] data, final boolean chunked) {
        if (data != null && data.length > 0) {
            if (chunked) {
                return BASE64_CHUNKED_ENCODER.encodeToString(data).trim();
            }
            return BASE64_UNCHUNKED_ENCODER.encodeToString(data).trim();
        }
        return StringUtils.EMPTY;
    }
269070
public static final String base64Decode(String str, String enc) throws UnsupportedEncodingException {
        if (str == null) {
            return null;
        } else {
            byte data[] = getBytes(str);
            return base64Decode(new String(data, enc));
        }

    }
507773
public static byte[] fromBase64(String base64String) {

        byte[] result = null;
        if (base64String != null) {
            result = Base64.decodeBase64(base64String);
        }
        return result;
    }