java.security

Class Signature

    • Field Detail

      • UNINITIALIZED

        protected static final int UNINITIALIZED
        Possible state value which signifies that this instance has not yet been initialized.
        See Also:
        Constant Field Values
      • SIGN

        protected static final int SIGN
        Possible state value which signifies that this instance has been initialized for signing purposes.
        See Also:
        Constant Field Values
      • VERIFY

        protected static final int VERIFY
        Possible state value which signifies that this instance has been initialized for verification purposes.
        See Also:
        Constant Field Values
      • state

        protected int state
        Current sate of this instance.
    • Constructor Detail

      • Signature

        protected Signature(String algorithm)
        Constructs a new Signature instance for a designated digital signature algorithm.
        Parameters:
        algorithm - the algorithm to use.
    • Method Detail

      • initVerify

        public final void initVerify(Certificate certificate)
                              throws InvalidKeyException
        Verify a signature with a designated Certificate. This is a FIPS 140-1 compatible method since it verifies a signature with a certificate.

        If the Certificate is an X.509 one, has a KeyUsage parameter and that parameter indicates this key is not to be used for signing then an exception is thrown.

        Parameters:
        certificate - a Certificate containing a public key to verify with.
        Throws:
        InvalidKeyException - if the key is invalid.
      • sign

        public final byte[] sign()
                          throws SignatureException
        Returns the signature bytes of all the data fed to this instance. The format of the output depends on the underlying signature algorithm.
        Returns:
        the signature bytes.
        Throws:
        SignatureException - if the engine is not properly initialized.
      • sign

        public final int sign(byte[] outbuf,
               int offset,
               int len)
                       throws SignatureException
        Generates signature bytes of all the data fed to this instance and stores it in the designated array. The format of the result depends on the underlying signature algorithm.

        After calling this method, the instance is reset to its initial state and can then be used to generate additional signatures.

        IMPLEMENTATION NOTE: Neither this method nor the GNU provider will return partial digests. If len is less than the signature length, this method will throw a SignatureException. If it is greater than or equal then it is ignored.

        Parameters:
        outbuf - array of bytes of where to store the resulting signature bytes.
        offset - the offset to start at in the array.
        len - the number of the bytes to use in the array.
        Returns:
        the real number of bytes used.
        Throws:
        SignatureException - if the engine is not properly initialized.
        Since:
        1.2
      • verify

        public final boolean verify(byte[] signature)
                             throws SignatureException
        Verifies a designated signature.
        Parameters:
        signature - the signature bytes to verify.
        Returns:
        true if verified, false otherwise.
        Throws:
        SignatureException - if the engine is not properly initialized or the signature does not check.
      • verify

        public final boolean verify(byte[] signature,
                     int offset,
                     int length)
                             throws SignatureException
        Verifies a designated signature.
        Parameters:
        signature - the signature bytes to verify.
        offset - the offset to start at in the array.
        length - the number of the bytes to use from the array.
        Returns:
        true if verified, false otherwise.
        Throws:
        IllegalArgumentException - if the signature byte array is null, or the offset or length is less than 0, or the sum of the offset and length is greater than the length of the signature byte array.
        SignatureException - if the engine is not properly initialized or the signature does not check.
      • update

        public final void update(byte b)
                          throws SignatureException
        Updates the data to be signed or verified with the specified byte.
        Parameters:
        b - the byte to update with.
        Throws:
        SignatureException - if the engine is not properly initialized.
      • update

        public final void update(byte[] data)
                          throws SignatureException
        Updates the data to be signed or verified with the specified bytes.
        Parameters:
        data - the array of bytes to use.
        Throws:
        SignatureException - if the engine is not properly initialized.
      • update

        public final void update(byte[] data,
                  int off,
                  int len)
                          throws SignatureException
        Updates the data to be signed or verified with the specified bytes.
        Parameters:
        data - an array of bytes to use.
        off - the offset to start at in the array.
        len - the number of bytes to use from the array.
        Throws:
        SignatureException - if the engine is not properly initialized.
      • getAlgorithm

        public final String getAlgorithm()
        Returns the name of the algorithm currently used. The names of algorithms are usually SHA/DSA or SHA/RSA.
        Returns:
        name of algorithm.
      • setParameter

        public final void setParameter(String param,
                        Object value)
                                throws InvalidParameterException
        Deprecated. use the other setParameter
        Sets the specified algorithm parameter to the specified value.
        Parameters:
        param - the parameter name.
        value - the parameter value.
        Throws:
        InvalidParameterException - if the parameter is invalid, the parameter is already set and can not be changed, a security exception occured, etc.
      • getParameters

        public final AlgorithmParameters getParameters()
        Return the parameters of the algorithm used in this instance as an AlgorithmParameters.
        Returns:
        the parameters used with this instance, or null if this instance does not use any parameters.