Class ChallengeResponseUtil
- java.lang.Object
-
- com.github.toolarium.security.util.ChallengeResponseUtil
-
public final class ChallengeResponseUtil extends java.lang.ObjectThis class implements method which can be used for a challenge/response protocol. The challenge is a base64 coded random number which can be created by the method
getChallenge.The method
checkResponsechecks a given response which should be signed with aPrivateKey.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckResponse(java.lang.String provider, java.lang.String algorithm, java.security.PublicKey publicKey, byte[] challenge, byte[] response)Checks the response given against the challenge verified with the certificate's public keybooleancheckResponse(java.lang.String algorithm, java.security.PublicKey publicKey, byte[] challenge, byte[] response)Checks the response given against the challenge verified with the certificate's public keybyte[]generateResponse(java.lang.String provider, java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] challenge)Generates a response based on the given challenge and private key using the specified algorithm and providerbyte[]generateResponse(java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] challenge)Generates a response based on the given challenge and private key using the specified algorithm and providerbyte[]getChallenge(int size)Returns a random number as base64 encoded stringstatic ChallengeResponseUtilgetInstance()Get the instance
-
-
-
Method Detail
-
getInstance
public static ChallengeResponseUtil getInstance()
Get the instance- Returns:
- the instance
-
getChallenge
public byte[] getChallenge(int size) throws java.security.GeneralSecurityExceptionReturns a random number as base64 encoded string- Parameters:
size- the size in byte- Returns:
- a random number of the given size with base64 encoded
- Throws:
java.security.GeneralSecurityException- in case of error
-
checkResponse
public boolean checkResponse(java.lang.String algorithm, java.security.PublicKey publicKey, byte[] challenge, byte[] response) throws java.security.GeneralSecurityExceptionChecks the response given against the challenge verified with the certificate's public key- Parameters:
algorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...publicKey- the public keychallenge- the base64 encoded challengeresponse- the base64 encoded response- Returns:
- true if the verification of the response is identical.
- Throws:
java.security.GeneralSecurityException- in case of error
-
checkResponse
public boolean checkResponse(java.lang.String provider, java.lang.String algorithm, java.security.PublicKey publicKey, byte[] challenge, byte[] response) throws java.security.GeneralSecurityExceptionChecks the response given against the challenge verified with the certificate's public key- Parameters:
provider- the provideralgorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...publicKey- the public keychallenge- the base64 encoded challengeresponse- the base64 encoded response- Returns:
- true if the verification of the response is identical.
- Throws:
java.security.GeneralSecurityException- in case of error
-
generateResponse
public byte[] generateResponse(java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] challenge) throws java.security.GeneralSecurityExceptionGenerates a response based on the given challenge and private key using the specified algorithm and provider- Parameters:
algorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...challenge- the base64 encoded challengeprivateKey- the private key as string- Returns:
- the signed response
- Throws:
java.security.GeneralSecurityException- in case of error
-
generateResponse
public byte[] generateResponse(java.lang.String provider, java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] challenge) throws java.security.GeneralSecurityExceptionGenerates a response based on the given challenge and private key using the specified algorithm and provider- Parameters:
provider- the provideralgorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...privateKey- the private keychallenge- the base64 encoded challenge- Returns:
- the signed response
- Throws:
java.security.GeneralSecurityException- in case of error
-
-