Package org.xipki.util
Class Base64Url
- java.lang.Object
-
- org.xipki.util.Base64Url
-
public class Base64Url extends java.lang.ObjectThis is an implementation of Base64Url based on the fast Base64 implementation of Mikael Grev.
-
-
Constructor Summary
Constructors Constructor Description Base64Url()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontainsOnlyBase64UrlChars(byte[] bytes, int offset, int len)static byte[]decodeFast(byte[] sArr)Decodes a BASE64Url encoded byte array that is known to be reasonably well formatted.static byte[]decodeFast(char[] sArr)Decodes a BASE64Url encoded char array that is known to be reasonably well formatted.static byte[]decodeFast(java.lang.String s)Decodes a BASE64Url encoded string that is known to be reasonably well formatted.static byte[]encodeToByte(byte[] sArr)Encodes a raw byte array into a BASE64Urlbyte[]representation i accordance with RFC 2045.static byte[]encodeToByte(byte[] sArr, boolean withPadding)static byte[]encodeToByteNoPadding(byte[] sArr)Encodes a raw byte array into a BASE64Urlbyte[]representation without padding i accordance with RFC 2045.static char[]encodeToChar(byte[] sArr)Encodes a raw byte array into a BASE64Urlchar[]representation i accordance with RFC 2045.static char[]encodeToChar(byte[] sArr, boolean withPadding)static char[]encodeToCharNoPadding(byte[] sArr)Encodes a raw byte array into a BASE64Urlchar[]representation i without padding accordance with RFC 2045.static java.lang.StringencodeToString(byte[] sArr)Encodes a raw byte array into a BASE64UrlStringrepresentation i accordance with RFC 2045.static java.lang.StringencodeToString(byte[] sArr, boolean withPadding)static java.lang.StringencodeToStringNoPadding(byte[] sArr)
-
-
-
Method Detail
-
containsOnlyBase64UrlChars
public static boolean containsOnlyBase64UrlChars(byte[] bytes, int offset, int len)
-
encodeToChar
public static char[] encodeToChar(byte[] sArr)
Encodes a raw byte array into a BASE64Urlchar[]representation i accordance with RFC 2045.- Parameters:
sArr- The bytes to convert. Ifnullor length 0 an empty array will be returned.- Returns:
- A BASE64Url encoded array. Never
null.
-
encodeToCharNoPadding
public static char[] encodeToCharNoPadding(byte[] sArr)
Encodes a raw byte array into a BASE64Urlchar[]representation i without padding accordance with RFC 2045.- Parameters:
sArr- The bytes to convert. Ifnullor length 0 an empty array will be returned.- Returns:
- A BASE64Url encoded array. Never
null.
-
encodeToChar
public static char[] encodeToChar(byte[] sArr, boolean withPadding)
-
decodeFast
public static byte[] decodeFast(char[] sArr)
Decodes a BASE64Url encoded char array that is known to be reasonably well formatted. The preconditions are:
+ The array must have no line separators at all (one line).
+ The array may not contain illegal characters within the encoded string
+ The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.- Parameters:
sArr- The source array. Length 0 will return an empty array.nullwill throw an exception.- Returns:
- The decoded array of bytes. May be of length 0.
-
encodeToByte
public static byte[] encodeToByte(byte[] sArr)
Encodes a raw byte array into a BASE64Urlbyte[]representation i accordance with RFC 2045.- Parameters:
sArr- The bytes to convert. Ifnullor length 0 an empty array will be returned.- Returns:
- A BASE64Url encoded array. Never
null.
-
encodeToByteNoPadding
public static byte[] encodeToByteNoPadding(byte[] sArr)
Encodes a raw byte array into a BASE64Urlbyte[]representation without padding i accordance with RFC 2045.- Parameters:
sArr- The bytes to convert. Ifnullor length 0 an empty array will be returned.- Returns:
- A BASE64Url encoded array. Never
null.
-
encodeToByte
public static byte[] encodeToByte(byte[] sArr, boolean withPadding)
-
decodeFast
public static byte[] decodeFast(byte[] sArr)
Decodes a BASE64Url encoded byte array that is known to be reasonably well formatted. The preconditions are:
+ The array must have no line separators at all (one line).
+ The array may not contain illegal characters within the encoded string
+ The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.- Parameters:
sArr- The source array. Length 0 will return an empty array.nullwill throw an exception.- Returns:
- The decoded array of bytes. May be of length 0.
-
encodeToString
public static java.lang.String encodeToString(byte[] sArr)
Encodes a raw byte array into a BASE64UrlStringrepresentation i accordance with RFC 2045.- Parameters:
sArr- The bytes to convert. Ifnullor length 0 an empty array will be returned.- Returns:
- A BASE64Url encoded array. Never
null.
-
encodeToStringNoPadding
public static java.lang.String encodeToStringNoPadding(byte[] sArr)
-
encodeToString
public static java.lang.String encodeToString(byte[] sArr, boolean withPadding)
-
decodeFast
public static byte[] decodeFast(java.lang.String s)
Decodes a BASE64Url encoded string that is known to be reasonably well formatted. The preconditions are:
+ The array must have no line separators at all (one line).
+ The array may not contain illegal characters within the encoded string
+ The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.- Parameters:
s- The source string. Length 0 will return an empty array.nullwill throw an exception.- Returns:
- The decoded array of bytes. May be of length 0.
-
-