Package org.apereo.cas.util
Class EncodingUtils
- java.lang.Object
-
- org.apereo.cas.util.EncodingUtils
-
public class EncodingUtils extends java.lang.ObjectThis isEncodingUtilsthat encapsulates common base64, signing and encryption calls and operations in one spot.- Since:
- 5.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringJSON_WEB_KEYJSON web key parameter that identifies the key..
-
Constructor Summary
Constructors Constructor Description EncodingUtils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static byte[]decodeBase64(byte[] data)Base64-decode the given string as byte[].static byte[]decodeBase64(java.lang.String data)Base64-decode the given string as byte[].static java.lang.StringdecodeBase64ToString(java.lang.String data)Base64-decode the given string as String.static byte[]decodeUrlSafeBase64(java.lang.String data)Base64-decode the given string as byte[].static java.lang.StringdecryptJwtValue(java.security.Key secretKeyEncryptionKey, java.lang.String value)Decrypt value based on the key created.static java.lang.StringencodeBase32(byte[] data, boolean chunked)Base32-encode the given byte[] as a string.static java.lang.StringencodeBase64(byte[] data)Base64-encode the given byte[] as a string.static java.lang.StringencodeBase64(byte[] data, boolean chunked)Base64-encode the given byte[] as a string.static java.lang.StringencodeBase64(java.lang.String data)Base64-encode the given string as a string.static byte[]encodeBase64ToByteArray(byte[] data)Base64-encode the given byte[] as a byte[].static java.lang.StringencodeUrlSafeBase64(byte[] data)Base64-encode the given byte[] as a string.static java.lang.StringencryptValueAsJwtDirectAes128Sha256(java.security.Key key, java.io.Serializable value)Encrypt value as jwt with direct algorithm and encryption content alg aes-128-sha-256.static java.lang.StringencryptValueAsJwtRsaOeap256Aes256Sha512(java.security.Key key, java.io.Serializable value)Encrypt value as jwt rsa oeap 256 aes 256 sha 512 string.static java.lang.StringgenerateJsonWebKey(int size)Generate octet json web key of given size .static java.security.KeygenerateJsonWebKey(java.lang.String secret)Prepare json web token key.static java.security.KeygenerateJsonWebKey(java.util.Map<java.lang.String,java.lang.Object> params)Generate json web key.static java.lang.StringhexDecode(char[] data)Hex decode string.static java.lang.StringhexDecode(java.lang.String data)Hex decode string.static java.lang.StringhexEncode(byte[] data)Hex encode string.static java.lang.StringhexEncode(java.lang.String data)Hex encode string.static booleanisBase64(java.lang.String value)Validates Base64 encoding.booleanisJsonWebKey(java.lang.String key)Is json web key boolean.static org.jose4j.jwk.JsonWebKeynewJsonWebKey(int size)New Json web key.static org.jose4j.jwk.JsonWebKeynewJsonWebKey(java.lang.String json)New Json web key.static java.util.Map<java.lang.String,java.lang.Object>parseJsonWebKey(java.lang.String key)Parse json web key map.static byte[]signJwsHMACSha256(java.security.Key key, byte[] value, java.util.Map<java.lang.String,java.lang.Object> headers)Sign jws hmac sha 256.static byte[]signJwsHMACSha512(java.security.Key key, byte[] value, java.util.Map<java.lang.String,java.lang.Object> headers)Sign jws.static byte[]signJwsRSASha512(java.security.Key key, byte[] value, java.util.Map<java.lang.String,java.lang.Object> headers)Sign jws.static java.lang.StringurlDecode(java.lang.String value)Url decode a value.static java.lang.StringurlEncode(java.lang.String value)Url encode a value via UTF-8.static java.lang.StringurlEncode(java.lang.String value, java.lang.String encoding)Url encode a value.static byte[]verifyJwsSignature(java.security.Key signingKey, byte[] value)Verify jws signature byte [ ].static byte[]verifyJwsSignature(java.security.Key signingKey, java.lang.String asString)Verify jws signature byte [ ].
-
-
-
Field Detail
-
JSON_WEB_KEY
public static final java.lang.String JSON_WEB_KEY
JSON web key parameter that identifies the key..- See Also:
- Constant Field Values
-
-
Method Detail
-
hexDecode
public static java.lang.String hexDecode(java.lang.String data)
Hex decode string.- Parameters:
data- the data- Returns:
- the string
-
hexDecode
public static java.lang.String hexDecode(char[] data)
Hex decode string.- Parameters:
data- the data- Returns:
- the string
-
hexEncode
public static java.lang.String hexEncode(java.lang.String data)
Hex encode string.- Parameters:
data- the data- Returns:
- the string
-
hexEncode
public static java.lang.String hexEncode(byte[] data)
Hex encode string.- Parameters:
data- the data- Returns:
- the string
-
encodeUrlSafeBase64
public static java.lang.String encodeUrlSafeBase64(byte[] data)
Base64-encode the given byte[] as a string.- Parameters:
data- the byte array to encode- Returns:
- the encoded string
-
decodeUrlSafeBase64
public static byte[] decodeUrlSafeBase64(java.lang.String data)
Base64-decode the given string as byte[].- Parameters:
data- the base64 string- Returns:
- the encoded array
-
encodeBase64
public static java.lang.String encodeBase64(byte[] data)
Base64-encode the given byte[] as a string.- Parameters:
data- the byte array to encode- Returns:
- the encoded string
-
encodeBase64
public static java.lang.String encodeBase64(byte[] data, boolean chunked)Base64-encode the given byte[] as a string.- Parameters:
data- the byte array to encodechunked- the chunked- Returns:
- the encoded string
-
encodeBase64
public static java.lang.String encodeBase64(java.lang.String data)
Base64-encode the given string as a string.- Parameters:
data- the String to encode- Returns:
- the encoded string
-
decodeBase64
public static byte[] decodeBase64(java.lang.String data)
Base64-decode the given string as byte[].- Parameters:
data- the base64 string- Returns:
- the decoded array
-
decodeBase64
public static byte[] decodeBase64(byte[] data)
Base64-decode the given string as byte[].- Parameters:
data- the base64 string- Returns:
- the decoded array
-
decodeBase64ToString
public static java.lang.String decodeBase64ToString(java.lang.String data)
Base64-decode the given string as String.- Parameters:
data- the base64 string- Returns:
- the string
-
encodeBase64ToByteArray
public static byte[] encodeBase64ToByteArray(byte[] data)
Base64-encode the given byte[] as a byte[].- Parameters:
data- the byte array to encode- Returns:
- the byte[] in base64
-
encodeBase32
public static java.lang.String encodeBase32(byte[] data, boolean chunked)Base32-encode the given byte[] as a string.- Parameters:
data- the byte array to encodechunked- the chunked- Returns:
- the encoded string
-
urlEncode
public static java.lang.String urlEncode(java.lang.String value)
Url encode a value via UTF-8.- Parameters:
value- the value to encode- Returns:
- the encoded value
-
urlEncode
public static java.lang.String urlEncode(java.lang.String value, java.lang.String encoding)Url encode a value.- Parameters:
value- the value to encodeencoding- the encoding- Returns:
- the encoded value
-
urlDecode
public static java.lang.String urlDecode(java.lang.String value)
Url decode a value.- Parameters:
value- the value to decode- Returns:
- the decoded value
-
isBase64
public static boolean isBase64(java.lang.String value)
Validates Base64 encoding.- Parameters:
value- the value to check- Returns:
- true if the string is validly Base64 encoded
-
verifyJwsSignature
public static byte[] verifyJwsSignature(java.security.Key signingKey, java.lang.String asString)Verify jws signature byte [ ].- Parameters:
signingKey- the signing keyasString- the as string- Returns:
- the byte [ ]
-
verifyJwsSignature
public static byte[] verifyJwsSignature(java.security.Key signingKey, byte[] value)Verify jws signature byte [ ].- Parameters:
value- the valuesigningKey- the signing key- Returns:
- the byte [ ]
-
isJsonWebKey
public boolean isJsonWebKey(java.lang.String key)
Is json web key boolean.- Parameters:
key- the key- Returns:
- true/false
-
newJsonWebKey
public static org.jose4j.jwk.JsonWebKey newJsonWebKey(java.lang.String json)
New Json web key.- Parameters:
json- the json- Returns:
- the json web key
-
newJsonWebKey
public static org.jose4j.jwk.JsonWebKey newJsonWebKey(int size)
New Json web key.- Parameters:
size- the size- Returns:
- the json web key
-
generateJsonWebKey
public static java.lang.String generateJsonWebKey(int size)
Generate octet json web key of given size .- Parameters:
size- the size- Returns:
- the key
-
generateJsonWebKey
public static java.security.Key generateJsonWebKey(java.lang.String secret)
Prepare json web token key.- Parameters:
secret- the secret- Returns:
- the key
-
generateJsonWebKey
public static java.security.Key generateJsonWebKey(java.util.Map<java.lang.String,java.lang.Object> params)
Generate json web key.- Parameters:
params- the params- Returns:
- the key
-
signJwsHMACSha512
public static byte[] signJwsHMACSha512(java.security.Key key, byte[] value, java.util.Map<java.lang.String,java.lang.Object> headers)Sign jws.- Parameters:
key- the keyvalue- the valueheaders- the headers- Returns:
- the byte []
-
signJwsHMACSha256
public static byte[] signJwsHMACSha256(java.security.Key key, byte[] value, java.util.Map<java.lang.String,java.lang.Object> headers)Sign jws hmac sha 256.- Parameters:
key- the keyvalue- the valueheaders- the headers- Returns:
- the byte [ ]
-
signJwsRSASha512
public static byte[] signJwsRSASha512(java.security.Key key, byte[] value, java.util.Map<java.lang.String,java.lang.Object> headers)Sign jws.- Parameters:
key- the keyvalue- the valueheaders- the headers- Returns:
- the byte []
-
encryptValueAsJwtDirectAes128Sha256
public static java.lang.String encryptValueAsJwtDirectAes128Sha256(java.security.Key key, java.io.Serializable value)Encrypt value as jwt with direct algorithm and encryption content alg aes-128-sha-256.- Parameters:
key- the keyvalue- the value- Returns:
- the string
-
encryptValueAsJwtRsaOeap256Aes256Sha512
public static java.lang.String encryptValueAsJwtRsaOeap256Aes256Sha512(java.security.Key key, java.io.Serializable value)Encrypt value as jwt rsa oeap 256 aes 256 sha 512 string.- Parameters:
key- the keyvalue- the value- Returns:
- the string
-
decryptJwtValue
public static java.lang.String decryptJwtValue(java.security.Key secretKeyEncryptionKey, java.lang.String value)Decrypt value based on the key created.- Parameters:
secretKeyEncryptionKey- the secret key encryption keyvalue- the value- Returns:
- the decrypted value
-
parseJsonWebKey
public static java.util.Map<java.lang.String,java.lang.Object> parseJsonWebKey(java.lang.String key) throws java.lang.ExceptionParse json web key map.- Parameters:
key- the key- Returns:
- the map
- Throws:
java.lang.Exception- the exception
-
-