Class Ltpa2Utils
java.lang.Object
de.sephirothj.spring.security.ltpa2.Ltpa2Utils
Utility class for operations on an LTPA2 token
- Author:
- Sephiroth
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondecryptLtpa2Token
(String encryptedToken, SecretKey key) decrypts an base64-encoded LTPA2 tokenencryptToken
(Ltpa2Token token, PrivateKey signerKey, SecretKey key) create a serialized, signed and encrypted LTPA2 tokenboolean
isSignatureValid
(String token, PublicKey signerKey) checks if the signature of the given token is validboolean
isTokenExpired
(String token) checks if the given token is expiredmakeInstance
(String tokenStr) create a new instance of Ltpa2Token from the given serialized LTPA2 tokensignToken
(String token, PrivateKey key) signs the given LTPA2 token
-
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 tokenkey
- the shared secret key that was used to encryptencryptedToken
- Returns:
- the serialized token
- Throws:
InvalidLtpa2TokenException
- in case something went wrong
-
makeInstance
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
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 verificationInvalidLtpa2TokenException
- 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 tokensignerKey
- the private key for signing the given tokenkey
- 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 creationInvalidLtpa2TokenException
- in case an error occured during encrypting the token
-