Class JwtSigner

java.lang.Object
com.xebialabs.xlrelease.plugins.jenkins.JwtSigner

public class JwtSigner extends Object
JwtSigner is a utility class for creating and signing JSON Web Tokens (JWTs). It supports multiple signing algorithms such as RSA and ECDSA.
  • Constructor Details

    • JwtSigner

      public JwtSigner()
  • Method Details

    • signJwt

      public static String signJwt(String algorithm, String privateKeyString, String privateKeyId, String audience, String issuer, String subject) throws Exception
      Signs a JWT using the specified algorithm and private key.
      Parameters:
      algorithm - The signing algorithm (e.g., RS256, ES256).
      privateKeyString - The private key in PEM format as a string.
      privateKeyId - The key ID to include in the JWT header (optional).
      audience - The audience claim for the JWT.
      issuer - The issuer claim for the JWT.
      subject - The subject claim for the JWT.
      Returns:
      The serialized JWT as a string.
      Throws:
      Exception - If an error occurs during signing or key conversion.
    • convertStringToPrivateKey

      public static PrivateKey convertStringToPrivateKey(String privateKeyString, String algorithm) throws Exception
      Converts a private key string in PEM format to a PrivateKey object.
      Parameters:
      privateKeyString - The private key in PEM format as a string.
      algorithm - The algorithm of the private key (e.g., RSA, EC).
      Returns:
      The PrivateKey object.
      Throws:
      Exception - If an error occurs during key conversion.