Class JdkTokenBuilder
java.lang.Object
uk.co.spudsoft.jwtvalidatorvertx.impl.AbstractTokenBuilder
uk.co.spudsoft.jwtvalidatorvertx.jdk.JdkTokenBuilder
- All Implemented Interfaces:
TokenBuilder
Implementation of TokenBuilder that uses the JDK
KeyPairGenerator
to generate key pairs.- Author:
- jtalbut
-
Field Summary
Fields inherited from class uk.co.spudsoft.jwtvalidatorvertx.impl.AbstractTokenBuilder
BASE64, keyCache, RANDOM
-
Constructor Summary
ConstructorsConstructorDescriptionJdkTokenBuilder
(com.google.common.cache.Cache<String, AlgorithmAndKeyPair> keyCache) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]
generateSignature
(String kid, JsonWebAlgorithm algorithm, String headerBase64, String claimsBase64) Sign the token header and claims using the specified key.static byte[]
generateSignature
(PrivateKey privateKey, JsonWebAlgorithm algorithm, String signingInput) Generate a signature using the JDK security classes.Methods inherited from class uk.co.spudsoft.jwtvalidatorvertx.impl.AbstractTokenBuilder
base64Claims, base64Header, base64JSon, base64Signature, buildToken, constructToken, generateClaimsNode, generateHeaderNode, setHeaderNotJson, setHeaderNotValidBase64, setKidInvalid, setPayloadNotJson, setPayloadNotValidBase64, setSignatureNotValidBase64, setSignatureNotValidHash
-
Constructor Details
-
JdkTokenBuilder
Constructor.- Parameters:
keyCache
- The key cache to be filled with keys created by the token builder.
-
-
Method Details
-
generateSignature
protected byte[] generateSignature(String kid, JsonWebAlgorithm algorithm, String headerBase64, String claimsBase64) throws Exception Description copied from class:AbstractTokenBuilder
Sign the token header and claims using the specified key.- Specified by:
generateSignature
in classAbstractTokenBuilder
- Parameters:
kid
- The key to use to sign the header and claims, if this key is not found in the cache it will be generated.algorithm
- The algorithm to use to generate the key, if it is not found in the cache.headerBase64
- The header to include in the signature.claimsBase64
- The claims to include in the signature.- Returns:
- The signature of the header and claims.
- Throws:
Exception
- If the security subsystem is unable to complete the operation.
-
generateSignature
public static byte[] generateSignature(PrivateKey privateKey, JsonWebAlgorithm algorithm, String signingInput) throws Exception Generate a signature using the JDK security classes.- Parameters:
privateKey
- The private key to sign the input with.algorithm
- The algorithm to use for the signing.signingInput
- The content to be signed.- Returns:
- A byte array containing the signature.
- Throws:
Exception
- If thrown by the JDK security subsystem.
-