This Signature class is used to provide the functionality of a
digital signature algorithm, such as RSA with MD5 or
DSA. Digital signatures are used for authentication and
integrity assurance of digital data.
Like other algorithm-based classes in Java Security, the
Signature class has two major components:
Digital Signature API (Application Program Interface)
This is the interface of methods called by applications needing
digital signature services. The API consists of all public methods.
Digital Signature SPI (Service Provider Interface)
This is the interface implemented by providers that supply
specific algorithms. It consists of all methods whose names are
prefixed by engine. Each such method is called by a
correspondingly-named public API method. For example, the
engineSign method is called by the
sign method. The SPI methods are abstract;
providers must supply a concrete implementation.
Also like other algorithm-based classes in Java Security, Signature
provides implementation-independent algorithms, whereby a caller
(application code) requests a particular signature algorithm
and is handed back a properly initialized Signature object. It is
also possible, if desired, to request a particular algorithm from a
particular provider. See the getInstance methods.
Thus, there are two ways to request a Signature algorithm object: by
specifying either just an algorithm name, or both an algorithm name
and a package provider.
If just an algorithm name is specified, the system will
determine if there is an implementation of the algorithm requested
available in the environment, and if there is more than one, if
there is a preferred one.
If both an algorithm name and a package provider are specified,
the system will determine if there is an implementation of the
algorithm in the package requested, and throw an exception if there
is not.
A Signature object can be used to generate and verify digital
signatures.
There are three phases to the use of a Signature object for
either signing data or verifying a signature:
Initialization, with either
a public key, which initializes the signature for
verification (see initVerify), or
a private key, which initializes the signature for
signing (see initSign).
Updating
Depending on the type of initialization, this will update the
bytes to be signed or verified. See the update methods.
Signing or Verifying
a signature on all updated bytes. See sign and verify.
Generates a Signature object implementing the specified
algorithm, as supplied from the specified provider, if such an
algorithm is available from the provider.
Returns a string representation of this signature object,
providing information that includes the state of the object
and the name of the algorithm used.
Generates a Signature object that implements the specified
algorithm. If the default provider package contains a Signature
subclass implementing the algorithm, an instance of that subclass
is returned. If the algorithm is not available in the default
package, other packages are searched.
Generates a Signature object implementing the specified
algorithm, as supplied from the specified provider, if such an
algorithm is available from the provider.
Returns the signature bytes of all the data updated. The
signature returned is X.509-encoded.
A call to this method resets this signature object to the state
it was in when previously initialized for signing via a
call to initSign(PrivateKey). That is, the object is
reset and available to generate another signature from the same
signer, if desired, via new calls to update and
sign.
Returns:
the signature bytes of the signing operation's result.
Verifies the passed-in signature. The signature bytes are expected
to be X.509-encoded.
A call to this method resets this signature object to the state
it was in when previously initialized for verification via a
call to initVerify(PublicKey). That is, the object is
reset and available to verify another signature from the identity
whose public key was specified in the call to initVerify.
Returns a string representation of this signature object,
providing information that includes the state of the object
and the name of the algorithm used.
Sets the specified algorithm parameter to the specified value.
This method supplies a general-purpose mechanism through
which it is possible to set the various parameters of this object.
A parameter may be any settable parameter for the algorithm, such as
a parameter size, or a source of random bits for signature generation
(if appropriate), or an indication of whether or not to perform
a specific but optional computation. A uniform algorithm-specific
naming scheme for each parameter is desirable but left unspecified
at this time.
if param is an
invalid parameter for this signature algorithm engine,
the parameter is already set
and cannot be set again, a security exception occurs, and so on.
Gets the value of the specified algorithm parameter. This method
supplies a general-purpose mechanism through which it is possible to
get the various parameters of this object. A parameter may be any
settable parameter for the algorithm, such as a parameter size, or
a source of random bits for signature generation (if appropriate),
or an indication of whether or not to perform a specific but optional
computation. A uniform algorithm-specific naming scheme for each
parameter is desirable but left unspecified at this time.
Parameters:
param - the string name of the parameter.
Returns:
the object that represents the parameter value, or null if
there is none.
SPI: Returns the signature bytes of all the data
updated so far. The signature returned is X.509-encoded.
For more information about the X.509 encoding, see
X.509 certificates.
Returns:
the signature bytes of the signing operation's result.
SPI: Verifies the passed-in signature. The signature bytes
are expected to be X.509-encoded. For more information about the
X.509 encoding, see X.509
certificates.
SPI: Sets the specified algorithm parameter to the specified
value. This method supplies a general-purpose mechanism through
which it is possible to set the various parameters of this object.
A parameter may be any settable parameter for the algorithm, such as
a parameter size, or a source of random bits for signature generation
(if appropriate), or an indication of whether or not to perform
a specific but optional computation. A uniform algorithm-specific
naming scheme for each parameter is desirable but left unspecified
at this time.
if param is an
invalid parameter for this signature algorithm engine,
the parameter is already set
and cannot be set again, a security exception occurs, and so on.
SPI: Gets the value of the specified algorithm parameter.
This method supplies a general-purpose mechanism through which it
is possible to get the various parameters of this object. A parameter
may be any settable parameter for the algorithm, such as a parameter
size, or a source of random bits for signature generation (if
appropriate), or an indication of whether or not to perform a
specific but optional computation. A uniform algorithm-specific
naming scheme for each parameter is desirable but left unspecified
at this time.
Parameters:
param - the string name of the parameter.
Returns:
the object that represents the parameter value, or null if
there is none.