Class SignatureUtil


  • public final class SignatureUtil
    extends Object
    Utility class for signing and verifying signatures.
    • Method Detail

      • getInstance

        public static SignatureUtil getInstance()
        Gets the SignatureUtil instance.
        Returns:
        The SignatureUtil singleton instance.
      • sign

        public byte[] sign​(PrivateKey privateKey,
                           String algorithm,
                           String message)
                    throws SignatureException
        Signs a String using the given private key. Uses the algorithm from the private key to perform the signature.
        Parameters:
        privateKey - The private key to use to sign the String.
        algorithm - The algorithm to use in the signing.
        message - The String to sign.
        Returns:
        The byte array of the signature.
        Throws:
        SignatureException - If there is a problem when performing the signature.
      • verify

        public boolean verify​(X509Certificate certificate,
                              String algorithm,
                              String message,
                              byte[] signatureData)
                       throws SignatureException
        Verifies a signature of a String using the certificate. Uses the algorithm from the certificate to perform the verification of the signature.
        Parameters:
        certificate - The X509Certificate to use to verify the signature.
        algorithm - The algorithm to use in the signing.
        message - The String that was signed.
        signatureData - The byte array of the signature.
        Returns:
        Whether or not the signature is valid for the String that was signed.
        Throws:
        SignatureException - If there is a problem when verifying the signature.
      • verify

        public boolean verify​(PublicKey publicKey,
                              String algorithm,
                              String message,
                              byte[] signatureData)
                       throws SignatureException
        Verifies a signature of a String using the public key. Uses the algorithm from the public key to perform the verification of the signature.
        Parameters:
        publicKey - The public key to use to verify the signature.
        algorithm - The algorithm to use in the signing.
        message - The String that was signed.
        signatureData - The byte array of the signature.
        Returns:
        Whether or not the signature is valid for the String that was signed.
        Throws:
        SignatureException - If there is a problem when verifying the signature.