java.security
Class Signature
java.lang.Object
|
+--java.security.SignatureSpi
|
+--java.security.Signature
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 getInstance. 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. Initialing
It must be initialized with a private key for signing.
It must be initialized with a public key for verifying.
2. Updating
Update the bytes for signing or verifying with calls to update.
3. Signing or Verify the signature on the currently stored
bytes by calling sign or verify.
Since:Author:- Mark Benvenuto <ivymccough@worldnet.att.net>
SIGN
protected static final int SIGN
Possible state variable which signifies if it has been
initialized for signing.
UNINITIALIZED
protected static final int UNINITIALIZED
Possible state variable which signifies if it has not been
initialized.
VERIFY
protected static final int VERIFY
Possible state variable which signifies if it has been
initialized for verifying.
state
protected int state
State of this Signature class.
Signature
protected Signature(java.lang.String algorithm)
Creates a new signature for this algorithm.
Parameters:
clone
public Object clone()
Returns a clone if cloneable.
Returns:
Throws:
getAlgorithm
public final String getAlgorithm()
Gets the name of the algorithm currently used.
The names of algorithms are usually SHA/DSA or SHA/RSA.
Returns:
getInstance
public static Signature getInstance(java.lang.String algorithm)
Gets an instance of the Signature class representing
the specified signature. If the algorithm is not found then,
it throws NoSuchAlgorithmException.
Parameters:
Returns:
- a Signature repesenting the desired algorithm
Throws:
getInstance
public static Signature getInstance(java.lang.String algorithm, java.lang.String provider)
Gets an instance of the Signature class representing
the specified signature from the specified provider. If the
algorithm is not found then, it throws NoSuchAlgorithmException.
If the provider is not found, then it throws
NoSuchProviderException.
Parameters:
Returns:
- a Signature repesenting the desired algorithm
Throws:
getParameter
public final Object getParameter(java.lang.String param)
Gets the value for the specified algorithm parameter.
Parameters:
Returns:
Throws:
getProvider
public final Provider getProvider()
Gets the provider that the Signature is from.
Returns:
- the provider of this Signature
initSign
public final void initSign(java.security.PrivateKey privateKey)
Initializes this class with the private key for
signing purposes.
Parameters:
Throws:
initSign
public final void initSign(java.security.PrivateKey privateKey, java.security.SecureRandom random)
Initializes this class with the private key and source
of randomness for signing purposes.
Since:Parameters:
Throws:
initVerify
public final void initVerify(java.security.PublicKey publicKey)
Initializes this class with the public key for
verification purposes.
Parameters:
Throws:
initVerify
public final void initVerify(java.security.cert.Certificate certificate)
Verify Signature with a certificate. This is a FIPS 140-1 compatible method
since it verifies a signature with a certificate.
If the certificate is an X.509 certificate, has a KeyUsage parameter and
the parameter indicates this key is not to be used for signing then an
error is returned.
Parameters:
setParameter
public final void setParameter(java.lang.String param, java.lang.Object value)
Sets the specified algorithm parameter to the specified value.
Parameters:
Throws:
setParameter
public final void setParameter(java.security.spec.AlgorithmParameterSpec params)
Sets the signature engine with the specified
AlgorithmParameterSpec;
By default this always throws UnsupportedOperationException
if not overridden;
Parameters:
Throws:
sign
public final byte[] sign()
Returns the signature bytes of all the data fed to this class.
The format of the output depends on the underlying signature
algorithm.
Returns:
Throws:
sign
public final int sign(byte[] outbuf, int offset, int len)
Generates signature bytes of all the data fed to this class
and outputs it to the passed array. The format of the
output depends on the underlying signature algorithm.
After calling this method, the signature is reset to its
initial state and can be used to generate additional
signatures.
Since:Parameters:
Returns:
- number of bytes in outbuf
Throws:
toString
public String toString()
Returns a representation of the Signature as a String
Returns:
- a string representing the signature
update
public final void update(byte b)
Updates the data to be signed or verified with the specified
byte.
Parameters:
Throws:
update
public final void update(byte[] )
Updates the data to be signed or verified with the specified
bytes.
Parameters:
Throws:
update
public final void update(byte[] , int off, int len)
Updates the data to be signed or verified with the specified
bytes.
Parameters:
Throws:
verify
public final boolean verify(byte[] )
Verifies the passed signature.
Parameters:
Returns:
- true if verified, false otherwise
Throws: