base64url in java

前端 未结 10 588
攒了一身酷
攒了一身酷 2020-12-05 06:49

https://web.archive.org/web/20110422225659/https://en.wikipedia.org/wiki/Base64#URL_applications

talks about base64Url - Decode


a modified Base64 for U

10条回答
  •  Happy的楠姐
    2020-12-05 07:17

    With the usage of Base64 from Apache Commons, who can be configured to URL safe, I created the following function:

    import org.apache.commons.codec.binary.Base64;
    
    public static String base64UrlDecode(String input) {
        String result = null;
        Base64 decoder = new Base64(true);
        byte[] decodedBytes = decoder.decode(input);
        result = new String(decodedBytes);
        return result;
    }
    

    The constructor Base64(true) makes the decoding URL-safe.

提交回复
热议问题