Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

java.security
Class Signature  view Signature download Signature.java

java.lang.Object
  extended byjava.security.SignatureSpi
      extended byjava.security.Signature
Direct Known Subclasses:
DummySignature

public abstract class Signature
extends SignatureSpi

Signature is used to provide an interface to digital signature algorithms. Digital signatures provide authentication and data integrity of digital data.

The GNU provider provides the NIST standard DSA which uses DSA and SHA-1. It can be specified by SHA/DSA, SHA-1/DSA or its OID. If the RSA signature algorithm is provided then it could be MD2/RSA. MD5/RSA, or SHA-1/RSA. The algorithm must be specified because there is no default.

Signature provides implementation-independent algorithms which are requested by the user through the getInstance() methods. It can be requested by specifying just the algorithm name or by specifying both the algorithm name and provider name.

The three phases of using Signature are:

  1. Initializing:
    • It must be initialized with a private key for signing.
    • It must be initialized with a public key for verifying.
    • Updating:

      Update the bytes for signing or verifying with calls to update.

    • Signing or Verify the signature on the currently stored bytes by calling sign or verify.


Field Summary
private  java.lang.String algorithm
           
(package private)  Provider provider
           
protected static int SIGN
          Possible state value which signifies that this instance has been initialized for signing purposes.
private static java.lang.String SIGNATURE
          Service name for signatures.
protected  int state
          Current sate of this instance.
protected static int UNINITIALIZED
          Possible state value which signifies that this instance has not yet been initialized.
protected static int VERIFY
          Possible state value which signifies that this instance has been initialized for verification purposes.
 
Fields inherited from class java.security.SignatureSpi
appRandom
 
Constructor Summary
protected Signature(java.lang.String algorithm)
          Constructs a new Signature instance for a designated digital signature algorithm.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this instance.
 java.lang.String getAlgorithm()
          Returns the name of the algorithm currently used.
static Signature getInstance(java.lang.String algorithm)
          Returns an instance of Signature representing the specified signature.
static Signature getInstance(java.lang.String algorithm, Provider provider)
          Returns an instance of Signature representing the specified signature from the specified Provider.
static Signature getInstance(java.lang.String algorithm, java.lang.String provider)
          Returns an instance of Signature representing the specified signature from the named provider.
 java.lang.Object getParameter(java.lang.String param)
          Deprecated. use the other getParameter
 AlgorithmParameters getParameters()
          Return the parameters of the algorithm used in this instance as an AlgorithmParameters.
 Provider getProvider()
          Returns the Provider of this instance.
 void initSign(PrivateKey privateKey)
          Initializes this class with the private key for signing purposes.
 void initSign(PrivateKey privateKey, SecureRandom random)
          Initializes this class with the private key and source of randomness for signing purposes.
 void initVerify(java.security.cert.Certificate certificate)
          Verify a signature with a designated Certificate.
 void initVerify(PublicKey publicKey)
          Initializes this instance with the public key for verification purposes.
 void setParameter(java.security.spec.AlgorithmParameterSpec params)
          Sets the signature engine with the specified java.security.spec.AlgorithmParameterSpec.
 void setParameter(java.lang.String param, java.lang.Object value)
          Deprecated. use the other setParameter
 byte[] sign()
          Returns the signature bytes of all the data fed to this instance.
 int sign(byte[] outbuf, int offset, int len)
          Generates signature bytes of all the data fed to this instance and stores it in the designated array.
 java.lang.String toString()
          Returns a rstring representation of this instance.
 void update(byte b)
          Updates the data to be signed or verified with the specified byte.
 void update(byte[] data)
          Updates the data to be signed or verified with the specified bytes.
 void update(byte[] data, int off, int len)
          Updates the data to be signed or verified with the specified bytes.
 boolean verify(byte[] signature)
          Verifies a designated signature.
 boolean verify(byte[] signature, int offset, int length)
          Verifies a designated signature.
 
Methods inherited from class java.security.SignatureSpi
engineGetParameter, engineGetParameters, engineInitSign, engineInitSign, engineInitVerify, engineSetParameter, engineSetParameter, engineSign, engineSign, engineUpdate, engineUpdate, engineVerify, engineVerify
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SIGNATURE

private static final java.lang.String SIGNATURE
Service name for signatures.

See Also:
Constant Field Values

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.


algorithm

private java.lang.String algorithm

provider

Provider provider
Constructor Detail

Signature

protected Signature(java.lang.String algorithm)
Constructs a new Signature instance for a designated digital signature algorithm.

Method Detail

getInstance

public static Signature getInstance(java.lang.String algorithm)
                             throws NoSuchAlgorithmException
Returns an instance of Signature representing the specified signature.


getInstance

public static Signature getInstance(java.lang.String algorithm,
                                    java.lang.String provider)
                             throws NoSuchAlgorithmException,
                                    NoSuchProviderException
Returns an instance of Signature representing the specified signature from the named provider.


getInstance

public static Signature getInstance(java.lang.String algorithm,
                                    Provider provider)
                             throws NoSuchAlgorithmException
Returns an instance of Signature representing the specified signature from the specified Provider.


getProvider

public final Provider getProvider()
Returns the Provider of this instance.


initVerify

public final void initVerify(PublicKey publicKey)
                      throws InvalidKeyException
Initializes this instance with the public key for verification purposes.


initVerify

public final void initVerify(java.security.cert.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.


initSign

public final void initSign(PrivateKey privateKey)
                    throws InvalidKeyException
Initializes this class with the private key for signing purposes.


initSign

public final void initSign(PrivateKey privateKey,
                           SecureRandom random)
                    throws InvalidKeyException
Initializes this class with the private key and source of randomness for signing purposes.


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.


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.

Since:
1.2

verify

public final boolean verify(byte[] signature)
                     throws SignatureException
Verifies a designated signature.


verify

public final boolean verify(byte[] signature,
                            int offset,
                            int length)
                     throws SignatureException
Verifies a designated signature.


update

public final void update(byte b)
                  throws SignatureException
Updates the data to be signed or verified with the specified byte.


update

public final void update(byte[] data)
                  throws SignatureException
Updates the data to be signed or verified with the specified bytes.


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.


getAlgorithm

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


toString

public java.lang.String toString()
Returns a rstring representation of this instance.


setParameter

public final void setParameter(java.lang.String param,
                               java.lang.Object value)
                        throws InvalidParameterException
Deprecated. use the other setParameter

Sets the specified algorithm parameter to the specified value.


setParameter

public final void setParameter(java.security.spec.AlgorithmParameterSpec params)
                        throws InvalidAlgorithmParameterException
Sets the signature engine with the specified java.security.spec.AlgorithmParameterSpec.

By default, and unless overriden by the concrete SPI, this method always throws an java.lang.UnsupportedOperationException.


getParameters

public final AlgorithmParameters getParameters()
Return the parameters of the algorithm used in this instance as an AlgorithmParameters.


getParameter

public final java.lang.Object getParameter(java.lang.String param)
                                    throws InvalidParameterException
Deprecated. use the other getParameter

Returns the value for the specified algorithm parameter.


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a clone of this instance.

Overrides:
clone in class SignatureSpi