Class JdkTokenBuilder

java.lang.Object
uk.co.spudsoft.jwtvalidatorvertx.impl.AbstractTokenBuilder
uk.co.spudsoft.jwtvalidatorvertx.jdk.JdkTokenBuilder
All Implemented Interfaces:
TokenBuilder

public class JdkTokenBuilder extends AbstractTokenBuilder
Implementation of TokenBuilder that uses the JDK KeyPairGenerator to generate key pairs.
Author:
jtalbut
  • Constructor Details

    • JdkTokenBuilder

      public JdkTokenBuilder(com.google.common.cache.Cache<String,AlgorithmAndKeyPair> keyCache)
      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 class AbstractTokenBuilder
      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.