Class StrictBase64Url

java.lang.Object
io.jans.lock.trace.crypto.StrictBase64Url

public final class StrictBase64Url extends Object
Strict base64url (RFC 4648 §5) codec without padding, as required by JWK x members (RFC 7517 / RFC 8037) and JWS signatures (RFC 7515 §2, "Base64url Encoding").

decode(String) accepts only the 64-character URL-safe alphabet, no padding, no whitespace, a length of 0, 2 or 3 (mod 4), and only canonical encodings (the unused trailing bits of the last character must be zero). Everything else is rejected with IllegalArgumentException, unlike the lenient commons-codec based io.jans.as.model.util.Base64Util.

Author:
Yuriy Movchan
  • Method Details

    • encode

      public static String encode(byte[] bytes)
      Returns:
      the unpadded base64url encoding of bytes
      Throws:
      IllegalArgumentException - if bytes is null
    • decode

      public static byte[] decode(String s)
      Returns:
      the decoded bytes; an empty string decodes to an empty array
      Throws:
      IllegalArgumentException - if s is null, contains a character outside [A-Za-z0-9_-] (this includes padding and whitespace), has length 1 (mod 4), or is not the canonical encoding of its decoded value