Class ChallengeResponseUtil


  • public final class ChallengeResponseUtil
    extends java.lang.Object

    This 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 checkResponse checks a given response which should be signed with a PrivateKey.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkResponse​(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 key
      boolean checkResponse​(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 key
      byte[] 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 provider
      byte[] 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 provider
      byte[] getChallenge​(int size)
      Returns a random number as base64 encoded string
      static ChallengeResponseUtil getInstance()
      Get the instance
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getChallenge

        public byte[] getChallenge​(int size)
                            throws java.security.GeneralSecurityException
        Returns 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.GeneralSecurityException
        Checks the response given against the challenge verified with the certificate's public key
        Parameters:
        algorithm - the algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        publicKey - the public key
        challenge - the base64 encoded challenge
        response - 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.GeneralSecurityException
        Checks the response given against the challenge verified with the certificate's public key
        Parameters:
        provider - the provider
        algorithm - the algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        publicKey - the public key
        challenge - the base64 encoded challenge
        response - 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.GeneralSecurityException
        Generates 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 challenge
        privateKey - 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.GeneralSecurityException
        Generates a response based on the given challenge and private key using the specified algorithm and provider
        Parameters:
        provider - the provider
        algorithm - the algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        privateKey - the private key
        challenge - the base64 encoded challenge
        Returns:
        the signed response
        Throws:
        java.security.GeneralSecurityException - in case of error