JOSE utilities class.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Base64.EncoderBase64URL encoder without padding.static final SecureRandomDefault secure random. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]generateInitializationVector(SecureRandom secureRandom, int length) Generates an initialization vector of the specified length using the specified secure random.static byte[]generateSalt(SecureRandom secureRandom, int length) Generates a salt of the specified length using the specified secure random.static byte[]toPaddedUnsignedBytes(BigInteger value, int length) Returns the integer value as an unsigned byte array of the specified length padded with leading zeros.static byte[]toUnsignedBytes(int value) Converts the specified integer value to unsigned byte array.static byte[]toUnsignedBytes(BigInteger value) Converts the specified integer value to unsigned byte array.static StringtoX509CertificateSha1Thumbprint(X509Certificate certificate) Returns the X.509 SHA1 thumbprint of the specified certificate.static StringtoX509CertificateSha256Thumbprint(X509Certificate certificate) Returns the X.509 SHA256 thumbprint of the specified certificate.
-
Field Details
-
DEFAULT_SECURE_RANDOM
Default secure random. -
BASE64_NOPAD_URL_ENCODER
Base64URL encoder without padding.
-
-
Constructor Details
-
JOSEUtils
public JOSEUtils()
-
-
Method Details
-
toPaddedUnsignedBytes
public static byte[] toPaddedUnsignedBytes(BigInteger value, int length) throws JWKProcessingException Returns the integer value as an unsigned byte array of the specified length padded with leading zeros.
In RFC7518 Section 6.2 it is not clearly specify that x, y and d must be converted to unsigned byte arrays however it is specified that their size must be that of a coordinate for the specified curve as a result we must get rid of the sign bit. Note that elliptic curve coordinates are always positive integers.
- Parameters:
value- an integerlength- the length- Returns:
- a byte array
- Throws:
JWKProcessingException
-
toUnsignedBytes
Converts the specified integer value to unsigned byte array.
- Parameters:
value- the integer to convert- Returns:
- the integer as unsigned byte array
-
toUnsignedBytes
public static byte[] toUnsignedBytes(int value) Converts the specified integer value to unsigned byte array.
- Parameters:
value- the integer to convert- Returns:
- the integer as unsigned byte array
-
generateInitializationVector
Generates an initialization vector of the specified length using the specified secure random.
- Parameters:
secureRandom- a secure randomlength- the initialization vector length- Returns:
- an initialization vector
-
generateSalt
Generates a salt of the specified length using the specified secure random.
- Parameters:
secureRandom- a secure randomlength- the initialization vector length- Returns:
- a salt
-
toX509CertificateSha1Thumbprint
public static String toX509CertificateSha1Thumbprint(X509Certificate certificate) throws JWKProcessingException Returns the X.509 SHA1 thumbprint of the specified certificate.
- Parameters:
certificate- an X.509 certificate- Returns:
- an X.509 SHA1 thumbprint
- Throws:
JWKProcessingException- if there was an error generating the thumbprint
-
toX509CertificateSha256Thumbprint
public static String toX509CertificateSha256Thumbprint(X509Certificate certificate) throws JWKProcessingException Returns the X.509 SHA256 thumbprint of the specified certificate.
- Parameters:
certificate- an X.509 certificate- Returns:
- an X.509 SHA1 thumbprint
- Throws:
JWKProcessingException- if there was an error generating the thumbprint
-