public final class EncodingUtils
extends java.lang.Object
EncodingUtils
that encapsulates common base64, signing and encryption calls and operations in one spot.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_CONTENT_ENCRYPTION_ALGORITHM
Default content encryption algorithm.
|
static java.lang.String |
JSON_WEB_KEY
JSON web key parameter that identifies the key..
|
Modifier and Type | Method and 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.String |
decodeBase64ToString(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.String |
decryptJwtValue(java.security.Key secretKeyEncryptionKey,
java.lang.String value)
Decrypt value based on the key created.
|
static java.lang.String |
encodeBase64(byte[] data)
Base64-encode the given byte[] as a string.
|
static java.lang.String |
encodeBase64(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.String |
encodeUrlSafeBase64(byte[] data)
Base64-encode the given byte[] as a string.
|
static java.lang.String |
encryptValueAsJwt(java.security.Key secretKeyEncryptionKey,
java.io.Serializable value,
java.lang.String algorithmHeaderValue,
java.lang.String contentEncryptionAlgorithmIdentifier)
Encrypt the value based on the seed array whose length was given during afterPropertiesSet,
and the key and content encryption ids.
|
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.
|
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.
|
static java.lang.String |
generateJsonWebKey(int size)
Generate octet json web key of given size .
|
static java.security.Key |
generateJsonWebKey(java.lang.String secret)
Prepare json web token key.
|
static java.lang.String |
hexDecode(char[] data)
Hex decode string.
|
static java.lang.String |
hexDecode(java.lang.String data)
Hex decode string.
|
static java.lang.String |
hexEncode(byte[] data)
Hex encode string.
|
static java.lang.String |
hexEncode(java.lang.String data)
Hex encode string.
|
static boolean |
isBase64(java.lang.String value)
Validates Base64 encoding.
|
static byte[] |
signJws(java.security.Key key,
byte[] value,
java.lang.String algHeaderValue)
Sign jws.
|
static byte[] |
signJwsHMACSha512(java.security.Key key,
byte[] value)
Sign jws.
|
static byte[] |
signJwsRSASha512(java.security.PrivateKey key,
byte[] value)
Sign jws.
|
static java.lang.String |
urlDecode(java.lang.String value)
Url decode a value.
|
static java.lang.String |
urlEncode(java.lang.String value)
Url encode a value via UTF-8.
|
static java.lang.String |
urlEncode(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 [ ].
|
public static final java.lang.String DEFAULT_CONTENT_ENCRYPTION_ALGORITHM
public static final java.lang.String JSON_WEB_KEY
public static java.lang.String hexDecode(java.lang.String data)
data
- the datapublic static java.lang.String hexDecode(char[] data)
data
- the datapublic static java.lang.String hexEncode(java.lang.String data)
data
- the datapublic static java.lang.String hexEncode(byte[] data)
data
- the datapublic static java.lang.String encodeUrlSafeBase64(byte[] data)
data
- the byte array to encodepublic static byte[] decodeUrlSafeBase64(java.lang.String data)
data
- the base64 stringpublic static java.lang.String encodeBase64(byte[] data)
data
- the byte array to encodepublic static java.lang.String encodeBase64(java.lang.String data)
data
- the String to encodepublic static byte[] decodeBase64(java.lang.String data)
data
- the base64 stringpublic static byte[] decodeBase64(byte[] data)
data
- the base64 stringpublic static java.lang.String decodeBase64ToString(java.lang.String data)
data
- the base64 stringpublic static byte[] encodeBase64ToByteArray(byte[] data)
data
- the byte array to encodepublic static java.lang.String urlEncode(java.lang.String value)
value
- the value to encodepublic static java.lang.String urlEncode(java.lang.String value, java.lang.String encoding)
value
- the value to encodeencoding
- the encodingpublic static java.lang.String urlDecode(java.lang.String value)
value
- the value to decodepublic static boolean isBase64(java.lang.String value)
value
- the value to checkpublic static byte[] verifyJwsSignature(java.security.Key signingKey, byte[] value)
value
- the valuesigningKey
- the signing keypublic static java.lang.String generateJsonWebKey(int size)
size
- the sizepublic static java.security.Key generateJsonWebKey(java.lang.String secret)
secret
- the secretpublic static byte[] signJwsHMACSha512(java.security.Key key, byte[] value)
key
- the keyvalue
- the valuepublic static byte[] signJwsRSASha512(java.security.PrivateKey key, byte[] value)
key
- the keyvalue
- the valuepublic static byte[] signJws(java.security.Key key, byte[] value, java.lang.String algHeaderValue)
key
- the keyvalue
- the valuealgHeaderValue
- the alg header valuepublic static java.lang.String encryptValueAsJwtDirectAes128Sha256(java.security.Key key, java.io.Serializable value)
key
- the keyvalue
- the valuepublic static java.lang.String encryptValueAsJwtRsaOeap256Aes256Sha512(java.security.Key key, java.io.Serializable value)
key
- the keyvalue
- the valuepublic static java.lang.String encryptValueAsJwt(java.security.Key secretKeyEncryptionKey, java.io.Serializable value, java.lang.String algorithmHeaderValue, java.lang.String contentEncryptionAlgorithmIdentifier)
secretKeyEncryptionKey
- the secret key encryption keyvalue
- the valuealgorithmHeaderValue
- the algorithm header valuecontentEncryptionAlgorithmIdentifier
- the content encryption algorithm identifierpublic static java.lang.String decryptJwtValue(java.security.Key secretKeyEncryptionKey, java.lang.String value)
secretKeyEncryptionKey
- the secret key encryption keyvalue
- the value