Package io.fusionauth.jwt
Class JWTUtils
java.lang.Object
io.fusionauth.jwt.JWTUtils
Helper to generate new HMAC secrets, EC and RSA public / private key pairs and other fun things.
- Author:
- Daniel DeGroff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertFingerprintToThumbprint(String fingerprint) Convert a HEXSHA-1orSHA-256X.509 certificate fingerprint to anx5torx5t#256thumbprint respectively.static StringconvertThumbprintToFingerprint(String x5tHash) Convert an X.509 certificate thumbprint to a HEXSHA-1orSHA-256fingerprint respectively.static HeaderdecodeHeader(String encodedJWT) WARNING!! This is not a secure or safe way to decode a JWT, this will not perform any validation on the signature.static JWTdecodePayload(String encodedJWT) WARNING!! This is not a secure or safe way to decode a JWT, this will not perform any validation on the signature.static KeyPairGenerate a new public / private key pair using a 2048 bit RSA key.static KeyPairGenerate a new public / private key pair using a 256 bit EC key.static KeyPairGenerate a new public / private key pair using a 3072 bit RSA key.static KeyPairGenerate a new public / private key pair using a 384 bit EC key.static KeyPairGenerate a new public / private key pair using a 4096 bit RSA key.static KeyPairGenerate a new public / private key pair using a 521 bit EC key.static StringGenerate the JWK SHA-1 Thumbprint as per RFC 7638.static StringgenerateJWS_kid(String algorithm, JSONWebKey key) Generate the JWK Thumbprint as per RFC 7638.static StringGenerate the JWK SHA-256 Thumbprint as per RFC 7638.static StringgenerateJWS_x5t(byte[] derEncodedCertificate) Generate thex5t- the X.509 certificate thumbprint to be used in JWT header.static StringgenerateJWS_x5t(String encodedCertificate) Generate thex5t- the X.509 certificate thumbprint to be used in JWT header.static StringgenerateJWS_x5t(String algorithm, byte[] derEncodedCertificate) Generate thex5t- the X.509 certificate thumbprint to be used in JWT header.static StringgenerateJWS_x5t(String algorithm, String encodedCertificate) Generate thex5t- the X.509 certificate thumbprint to be used in JWT header.static StringgenerateSecureRandom(int bytes) Return a secure random stringstatic StringGenerate a 32 byte (256 bit) HMAC secret for use with a SHA-256 hash.static StringGenerate a 48 byte (384 bit) HMAC secret for use with a SHA-384 hash.static StringGenerate a 64 byte (512 bit) HMAC secret for use with a SHA-512 hash.
-
Constructor Details
-
JWTUtils
public JWTUtils()
-
-
Method Details
-
convertFingerprintToThumbprint
Convert a HEXSHA-1orSHA-256X.509 certificate fingerprint to anx5torx5t#256thumbprint respectively.- Parameters:
fingerprint- the SHA-1 or SHA-256 fingerprint- Returns:
- an x5t hash.
-
convertThumbprintToFingerprint
Convert an X.509 certificate thumbprint to a HEXSHA-1orSHA-256fingerprint respectively.If a
x5tthumbprint is provided, a SHA-1 HEX encoded fingerprint will be returned.If a
x5t#256thumbprint is provided, a SHA-256 HEX encoded fingerprint will be returned.- Parameters:
x5tHash- the x5t hash- Returns:
- a SHA-1 or SHA-256 fingerprint
-
decodeHeader
WARNING!! This is not a secure or safe way to decode a JWT, this will not perform any validation on the signature.Consider the header returned from this method as un-trustworthy. This is intended for utility and a nice way to read the JWT header, but do not use it in production to verify the integrity.
- Parameters:
encodedJWT- the encoded JWT- Returns:
- a Header object
-
decodePayload
WARNING!! This is not a secure or safe way to decode a JWT, this will not perform any validation on the signature.Consider the JWT returned from this method as un-trustworthy. This is intended for utility and a nice way to read the JWT, but do not use it in production to verify the claims contained in this JWT.
- Parameters:
encodedJWT- the encoded JWT- Returns:
- a JWT object
-
generate2048_RSAKeyPair
Generate a new public / private key pair using a 2048 bit RSA key. This is the minimum key length for use with an RSA signing scheme for JWT.- Returns:
- a public and private key PEM in their respective X.509 and PKCS#8 key formats.
-
generate256_ECKeyPair
Generate a new public / private key pair using a 256 bit EC key. A 256 bit EC key is roughly equivalent to a 3072 bit RSA key.- Returns:
- a public and private key PEM in their respective X.509 and PKCS#8 key formats.
-
generate3072_RSAKeyPair
Generate a new public / private key pair using a 3072 bit RSA key.- Returns:
- a public and private key PEM in their respective X.509 and PKCS#8 key formats.
-
generate384_ECKeyPair
Generate a new public / private key pair using a 384 bit EC key. A 384 bit EC key is roughly equivalent to a 7680 bit RSA key.- Returns:
- a public and private key PEM in their respective X.509 and PKCS#8 key formats.
-
generate4096_RSAKeyPair
Generate a new public / private key pair using a 4096 bit RSA key.- Returns:
- a public and private key PEM in their respective X.509 and PKCS#8 key formats.
-
generate521_ECKeyPair
Generate a new public / private key pair using a 521 bit EC key. A 521 bit EC key is roughly equivalent to a 15,360 bit RSA key.- Returns:
- a public and private key PEM in their respective X.509 and PKCS#8 key formats.
-
generateJWS_kid
Generate the JWK Thumbprint as per RFC 7638.- Parameters:
algorithm- the algorithm used to calculate the hash of the thumbprint, generally SHA-1 or SHA-256.key- theJSONWebKeyto determine the thumbprint for- Returns:
- the base64url-encoded JWK Thumbprint
-
generateJWS_kid
Generate the JWK SHA-1 Thumbprint as per RFC 7638.- Parameters:
key- theJSONWebKeyto determine the thumbprint for- Returns:
- the base64url-encoded JWK Thumbprint
-
generateJWS_kid_S256
Generate the JWK SHA-256 Thumbprint as per RFC 7638.- Parameters:
key- theJSONWebKeyto determine the thumbprint for- Returns:
- the base64url-encoded JWK Thumbprint
-
generateJWS_x5t
Generate thex5t- the X.509 certificate thumbprint to be used in JWT header.- Parameters:
encodedCertificate- the Base64 encoded certificate- Returns:
- an x5t hash.
-
generateJWS_x5t
Generate thex5t- the X.509 certificate thumbprint to be used in JWT header.- Parameters:
algorithm- the algorithm used to calculate the hash, generally SHA-1 or SHA-256.encodedCertificate- the Base64 encoded certificate- Returns:
- an x5t hash.
-
generateJWS_x5t
Generate thex5t- the X.509 certificate thumbprint to be used in JWT header.- Parameters:
derEncodedCertificate- the DER encoded certificate- Returns:
- an x5t hash.
-
generateJWS_x5t
Generate thex5t- the X.509 certificate thumbprint to be used in JWT header.- Parameters:
algorithm- the algorithm used to calculate the hash, generally SHA-1 or SHA-256.derEncodedCertificate- the DER encoded certificate- Returns:
- an x5t hash.
-
generateSHA256_HMACSecret
Generate a 32 byte (256 bit) HMAC secret for use with a SHA-256 hash.- Returns:
- a secret for use with an HMAC signing and verification scheme.
-
generateSHA384_HMACSecret
Generate a 48 byte (384 bit) HMAC secret for use with a SHA-384 hash.- Returns:
- a secret for use with an HMAC signing and verification scheme.
-
generateSHA512_HMACSecret
Generate a 64 byte (512 bit) HMAC secret for use with a SHA-512 hash.- Returns:
- a secret for use with an HMAC signing and verification scheme.
-
generateSecureRandom
Return a secure random string- Parameters:
bytes- the number of bytes used to generate the random byte array to be encoded.- Returns:
- a random string.
-