Class Ltpa2Utils

java.lang.Object
de.sephirothj.spring.security.ltpa2.Ltpa2Utils

public class Ltpa2Utils extends Object
Utility class for operations on an LTPA2 token
Author:
Sephiroth
  • Constructor Details

    • Ltpa2Utils

      public Ltpa2Utils()
  • Method Details

    • decryptLtpa2Token

      @NonNull public String decryptLtpa2Token(@NonNull String encryptedToken, @NonNull SecretKey key) throws InvalidLtpa2TokenException
      decrypts an base64-encoded LTPA2 token
      Parameters:
      encryptedToken - the base64-encoded and encrypted token
      key - the shared secret key that was used to encrypt encryptedToken
      Returns:
      the serialized token
      Throws:
      InvalidLtpa2TokenException - in case something went wrong
    • makeInstance

      @NonNull public Ltpa2Token makeInstance(@NonNull String tokenStr) throws InvalidLtpa2TokenException
      create a new instance of Ltpa2Token from the given serialized LTPA2 token
      Parameters:
      tokenStr - a serialized LTPA2 token (unencrypted)
      Returns:
      instance of Ltpa2Token
      Throws:
      InvalidLtpa2TokenException - if the token is malformed
    • isTokenExpired

      public boolean isTokenExpired(@NonNull String token) throws InvalidLtpa2TokenException
      checks if the given token is expired
      Parameters:
      token - a serialized LTPA2 token (unencrypted)
      Returns:
      whether the given token is expired or not
      Throws:
      InvalidLtpa2TokenException - if the token is malformed
      See Also:
    • isSignatureValid

      public boolean isSignatureValid(@NonNull String token, @NonNull PublicKey signerKey) throws InvalidLtpa2TokenException
      checks if the signature of the given token is valid
      Parameters:
      token - a serialized LTPA2 token (unencrypted)
      signerKey - the public key which corresponds to the private key that was used to sign an LTPA2 token
      Returns:
      whether the signature for the given token is valid or not
      Throws:
      InvalidLtpa2TokenException - in case an error occured during signature verification
      InvalidLtpa2TokenException - if the token is malformed
    • signToken

      @NonNull public String signToken(@NonNull String token, @NonNull PrivateKey key) throws InvalidLtpa2TokenException
      signs the given LTPA2 token
      Parameters:
      token - a serialized LTPA2 token (unencrypted)
      key - the private key for signing the given token
      Returns:
      the base64-encoded signature of the token
      Throws:
      InvalidLtpa2TokenException - in case an error occured during signature creation
      See Also:
    • encryptToken

      @NonNull public String encryptToken(@NonNull Ltpa2Token token, @NonNull PrivateKey signerKey, @NonNull SecretKey key) throws InvalidLtpa2TokenException
      create a serialized, signed and encrypted LTPA2 token
      Parameters:
      token - the token
      signerKey - the private key for signing the given token
      key - the shared secret key for encrypting the given token
      Returns:
      serialized, signed and encrypted LTPA2 token
      Throws:
      InvalidLtpa2TokenException - in case an error occured during signature creation
      InvalidLtpa2TokenException - in case an error occured during encrypting the token