Signaturepublic abstract class Signature extends Object This Signature class is used to provide applications
the functionality
of a digital signature algorithm. Digital signatures are used for
authentication and integrity assurance of digital data.
The signature algorithm can be, among others, the NIST standard
DSA, using DSA and SHA-1. The DSA algorithm using the
SHA-1 message digest algorithm can be specified as SHA1withDSA.
In the case of RSA, there are multiple choices for the message digest
algorithm, so the signing algorithm could be specified as, for example,
MD2withRSA, MD5withRSA, or SHA1withRSA.
The algorithm name must be specified, as there is no default.
When 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.
A Signature object can be used to generate and
verify digital signatures.
There are three phases to the use of a Signature
object for verifying a signature:
- Initialization, with a public key, which initializes the
signature for verification
- Updating
Depending on the type of initialization, this will update the
bytes to be verified.
- Verifying a signature on all updated bytes.
|
Constructors Summary |
---|
protected Signature()Protected constructor.
|
Methods Summary |
---|
public abstract java.lang.String | getAlgorithm()Gets the signature algorithm.
| public static com.sun.midp.crypto.Signature | getInstance(java.lang.String algorithm)Generates a Signature object that implements
the specified digest
algorithm.
if (algorithm == null) {
throw new NoSuchAlgorithmException();
}
algorithm = algorithm.toUpperCase();
try {
Class sigClass;
if (algorithm.equals("MD5WITHRSA")) {
sigClass = Class.forName("com.sun.midp.crypto.RsaMd5Sig");
} else if (algorithm.equals("SHA1WITHRSA")) {
sigClass = Class.forName("com.sun.midp.crypto.RsaShaSig");
} else {
throw new NoSuchAlgorithmException();
}
return (Signature)sigClass.newInstance();
} catch (Throwable e) {
throw new NoSuchAlgorithmException("Provider not found");
}
| public abstract int | getLength()Gets the byte length of the signature data.
| public abstract void | initSign(PrivateKey theKey)Initializes the Signature object with the appropriate
Key for signature creation.
| public abstract void | initVerify(PublicKey theKey)Initializes the Signature object with the appropriate
Key for signature verification.
| public int | sign(byte[] outbuf)Generates the signature of all/last input data. A call to this
method also resets this signature object to the state it was in
when previously initialized via a call to initSign() and the
message to sign given via a call to update().
That is, the object is reset and available to sign another message.
return sign(outbuf, 0, outbuf.length);
| public abstract int | sign(byte[] outbuf, int offset, int len)Generates the signature of all/last input data. A call to this
method also resets this signature object to the state it was in
when previously initialized via a call to initSign() and the
message to sign given via a call to update().
That is, the object is reset and available to sign another message.
| public abstract void | update(byte[] inBuf, int inOff, int inLen)Accumulates a signature of the input data. When this method is used,
temporary storage of intermediate results is required. This method
should only be used if all the input data required for the signature
is not available in one byte array. The sign() or verify() method is
recommended whenever possible.
| public boolean | verify(byte[] signature)Verifies the passed-in signature.
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 .
return verify(signature, 0, signature.length);
| public abstract boolean | verify(byte[] signature, int offset, int length)Verifies the passed-in signature.
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 .
|
|