Class SignatureUtil


  • public final class SignatureUtil
    extends java.lang.Object
    This class implements a simple interface to sign data and verify the signed data. The class works with the standard API of java and use public and private keys.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static SignatureUtil getInstance()
      Get the instance
      byte[] sign​(java.lang.String provider, java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] data)
      Sign data with the given algorithm and private key.
      byte[] sign​(java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] data)
      Sign data with the given algorithm and private key.
      boolean verify​(java.lang.String provider, java.lang.String algorithm, java.security.PublicKey publicKey, byte[] dataToVerify, byte[] dataToCompareWith)
      Verify a signed data.
      boolean verify​(java.lang.String algorithm, java.security.PublicKey publicKey, byte[] dataToVerify, byte[] dataToCompareWith)
      Verify a signed data.
      • Methods inherited from class java.lang.Object

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

      • getInstance

        public static SignatureUtil getInstance()
        Get the instance
        Returns:
        the instance
      • verify

        public boolean verify​(java.lang.String algorithm,
                              java.security.PublicKey publicKey,
                              byte[] dataToVerify,
                              byte[] dataToCompareWith)
                       throws java.security.GeneralSecurityException
        Verify a signed data.
        Parameters:
        algorithm - the algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        publicKey - the public key
        dataToVerify - the data to verify the signature
        dataToCompareWith - the data to compare with the signed data
        Returns:
        true if the verification of the response is identical.
        Throws:
        java.security.GeneralSecurityException - in case of error
      • verify

        public boolean verify​(java.lang.String provider,
                              java.lang.String algorithm,
                              java.security.PublicKey publicKey,
                              byte[] dataToVerify,
                              byte[] dataToCompareWith)
                       throws java.security.GeneralSecurityException
        Verify a signed data.
        Parameters:
        provider - the provider
        algorithm - the algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        publicKey - the public key
        dataToVerify - the data to verify the signature
        dataToCompareWith - the data to compare with the signed data
        Returns:
        true if the verification of the response is identical.
        Throws:
        java.security.GeneralSecurityException - in case of error
      • sign

        public byte[] sign​(java.lang.String algorithm,
                           java.security.PrivateKey privateKey,
                           byte[] data)
                    throws java.security.GeneralSecurityException
        Sign data with the given algorithm and private key.
        Parameters:
        algorithm - the algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        privateKey - the private key
        data - the data to sign
        Returns:
        the signed response
        Throws:
        java.security.GeneralSecurityException - in case of error
      • sign

        public byte[] sign​(java.lang.String provider,
                           java.lang.String algorithm,
                           java.security.PrivateKey privateKey,
                           byte[] data)
                    throws java.security.GeneralSecurityException
        Sign data with the given algorithm and private key.
        Parameters:
        provider - the provider
        algorithm - the algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        privateKey - the private key
        data - the data to sign
        Returns:
        the signed response
        Throws:
        java.security.GeneralSecurityException - in case of error