public abstract class DigitalSignature extends java.security.Signature implements ExtendedSignature
A digital signature algorithm is a cryptographic algorithm that provides signature generation and verification using a key pair. A digital signature is calculated over a message using a private key that is only known to the signer; the resulting signature is dependent on the private key and the content of the message. Another party can then use the corresponding public key (known to everyone) to verify that signature is valid, which indicates the message has not been modified since the signature was created and that the signer is in fact the entity that created the digital signature (data integrity, authentication, and non-repudiation). The private key must be kept secret since it provides the security of the algorithm; the algorithm itself
This architecture represents digital signature algorithms that require the original message as input to the verification algorithm. This class of digital signature algorithms are composed of two underlying components: a cryptographic hash function and an asymmetric cryptosystem.
Signature Generation
The signature generation process accepts a message and a private key as input
and produces a digital signature as output. It works as follows:
Signature Verification
The signature verification process accepts a message, a digital signature,
and a public key as input and produces a boolean indicator for whether or not
the message is valid as output. It works as follows:
A positive result from the signature verification process indicates that the message has not been modified since the signature was created and that the signature was created by the entity that has the private key which corresponds to the public key used during verification. A negative result from the signature verification process indicates that the message was modified since the signature was created and/or the signature was not created by the entity that has the private key which corresponds to the public key used during verification.
A digital signature algorithm instance can be obtained using the Java
Cryptography Architecture (JCA), by requesting the '<algorithm>'
algorithm from the Entrust cryptographic service provider. This can be done using the following
call:
Signature.getInstance("<algorithm>", "Entrust");
| Modifier | Constructor and Description |
|---|---|
protected |
DigitalSignature(java.lang.String algName,
boolean internalDigestImpl,
java.lang.String implSoftClassName,
java.lang.String implP11ClassName,
java.lang.String implCapiClassName,
java.lang.String implKeychainClassName)
The constructor; creates a new
DigitalSignature instance. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
assertParametersValid(java.security.spec.AlgorithmParameterSpec params)
Checks the parameters to ensure that they are valid and appropriate for
this digital signature algorithm.
|
protected java.lang.Object |
engineGetParameter(java.lang.String param)
Getting algorithm parameters using this method is not supported; this API
always throws an
InvalidParameterException. |
protected java.security.AlgorithmParameters |
engineGetParameters()
Return the parameters used with this signature algorithm, or
null if this signature algorithm does not use any
parameters. |
protected void |
engineInitSign(java.security.PrivateKey privateKey)
Initializes this signature object with the specified private key for
signing operations.
|
protected void |
engineInitSign(java.security.PrivateKey privateKey,
java.security.SecureRandom random)
Initializes this signature object with the specified private key and
source of randomness for signing operations.
|
protected void |
engineInitVerify(java.security.PublicKey publicKey)
Initializes this signature object with the specified public key for
verification operations.
|
protected void |
engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
Initializes the signature algorithm with the specified parameter set.
|
protected void |
engineSetParameter(java.lang.String param,
java.lang.Object value)
Setting algorithm parameters using this method is not supported; this API
always throws an
InvalidParameterException. |
protected byte[] |
engineSign()
Returns the signature bytes of all the data updated so far.
|
protected int |
engineSign(byte[] outbuf,
int offset,
int len)
Finishes this signature operation and stores the resulting signature
bytes in the provided buffer
outbuf, starting at
offset. |
protected void |
engineUpdate(byte b)
Updates the data to be signed or verified using the specified byte.
|
protected void |
engineUpdate(byte[] b,
int off,
int len)
Updates the data to be signed or verified, using the specified array of
bytes, starting at the specified offset.
|
protected boolean |
engineVerify(byte[] sigBytes)
Verifies the passed-in signature.
|
protected boolean |
engineVerify(byte[] sigBytes,
int offset,
int length)
Verifies the passed-in signature in the specified array of bytes,
starting at the specified offset.
|
protected java.security.spec.AlgorithmParameterSpec |
generateDefaultParameters()
Returns a default set of parameters that are valid and appropriate for
this digital signature algorithm.
|
byte[] |
getDigest()
Returns the digest that was calculated during signature generation or
verification.
|
protected abstract com.entrust.toolkit.security.crypto.signature.DigitalSignatureImpl |
getDigitalSignatureImpl(java.lang.String implClassName)
Instantiates the internal signature algorithm implementation from the
indicated class.
|
protected java.security.SecureRandom |
getPrng()
Returns the pseudo-random number generator (PRNG) to be used for
parameter generation.
|
protected java.security.AlgorithmParameters |
toAlgorithmParameters(java.security.spec.AlgorithmParameterSpec params)
Converts algorithm parameters in transparent representation into their
opaque representation during a call to
engineGetParameters()
. |
protected DigitalSignature(java.lang.String algName,
boolean internalDigestImpl,
java.lang.String implSoftClassName,
java.lang.String implP11ClassName,
java.lang.String implCapiClassName,
java.lang.String implKeychainClassName)
DigitalSignature instance.
algName - the name of the signature algorithm (JCE/JCA algorithm name)internalDigestImpl - indicates whether this digital signature algorithm supports
internal or external digest calculationimplSoftClassName - the name of the class containing the software implementation
of this algorithmimplP11ClassName - the name of the class containing the PKCS#11 implementation of
this algorithmimplCapiClassName - the name of the class containing the MSCAPI implementation of
this algorithmprotected final void engineInitSign(java.security.PrivateKey privateKey)
throws java.security.InvalidKeyException
engineInitSign in class java.security.SignatureSpiprivateKey - [FIPS 140-2 data input] [FIPS 140-2 CSP] the private key of
the identity whose signature will be generated.java.security.InvalidKeyException - [FIPS 140-2 status output] if the key is improperly encoded,
parameters are missing, and so on.Fips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected void engineInitSign(java.security.PrivateKey privateKey,
java.security.SecureRandom random)
throws java.security.InvalidKeyException
engineInitSign in class java.security.SignatureSpiprivateKey - [FIPS 140-2 data input] [FIPS 140-2 CSP] the private key of
the identity whose signature will be generated.random - [FIPS 140-2 control input] the source of randomnessjava.security.InvalidKeyException - [FIPS 140-2 status output] if the key is improperly encoded,
parameters are missing, and so on.Fips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final void engineInitVerify(java.security.PublicKey publicKey)
throws java.security.InvalidKeyException
engineInitVerify in class java.security.SignatureSpipublicKey - [FIPS 140-2 data input] [FIPS 140-2 CSP] the public key of the
identity whose signature is going to be verified.java.security.InvalidKeyException - [FIPS 140-2 status output] if the key is improperly encoded,
parameters are missing, and so on.Fips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final void engineUpdate(byte b)
throws java.security.SignatureException
engineUpdate in class java.security.SignatureSpib - [FIPS 140-2 data input] the byte to use for the updatejava.security.SignatureException - [FIPS 140-2 status output] if the algorithm is not
initialized properlyFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final void engineUpdate(byte[] b,
int off,
int len)
throws java.security.SignatureException
engineUpdate in class java.security.SignatureSpib - [FIPS 140-2 data input] the array of bytesoff - [FIPS 140-2 data input] the offset to start from in the array
of byteslen - [FIPS 140-2 data input] the number of bytes to use, starting
at offsetjava.security.SignatureException - [FIPS 140-2 status output] if the algorithm is not
initialized properlyFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final byte[] engineSign()
throws java.security.SignatureException
The format of the signature depends on the underlying signature scheme.
engineSign in class java.security.SignatureSpijava.security.SignatureException - [FIPS 140-2 status output] if the algorithm is not
initialized properlyFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final int engineSign(byte[] outbuf,
int offset,
int len)
throws java.security.SignatureException
outbuf, starting at
offset.
The format of the signature depends on the underlying signature scheme.
The signature implementation is reset to its initial state (the state it
was in after a call to one of the engineInitSign methods)
and can be reused to generate further signatures with the same private
key.
engineSign in class java.security.SignatureSpioutbuf - [FIPS 140-2 data output] buffer for the signature resultoffset - [FIPS 140-2 data input] offset into outbuf where
the signature is storedlen - [FIPS 140-2 data input] number of bytes within
outbuf allotted for the signature. This
implementation does not return partial digests. If the value
of this parameter is less than the actual signature length,
this method will throw a SignatureException. This
parameter is ignored if its value is greater than or equal to
the actual signature length.outbufjava.security.SignatureException - [FIPS 140-2 status output] if the algorithm is not
initialized properly, or an error occurs or len
is less than the actual signature lengthFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final boolean engineVerify(byte[] sigBytes)
throws java.security.SignatureException
engineVerify in class java.security.SignatureSpisigBytes - [FIPS 140-2 data input] the signature bytes to be verifiedtrue if the signature was
verified, false if notjava.security.SignatureException - [FIPS 140-2 status output] if the algorithm is not
initialized properly, or the passed-in signature is
improperly encoded or of the wrong type, etc.Fips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final boolean engineVerify(byte[] sigBytes,
int offset,
int length)
throws java.security.SignatureException
engineVerify in class java.security.SignatureSpisigBytes - [FIPS 140-2 data input] the signature bytes to be verifiedoffset - [FIPS 140-2 data input] the offset to start from in the array
of byteslength - [FIPS 140-2 data input] the number of bytes to use, starting
at offsettrue if the signature was
verified, false if notjava.security.SignatureException - [FIPS 140-2 status output] if the algorithm is not
initialized properly, or the passed-in signature is
improperly encoded or of the wrong type, etc.Fips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final void engineSetParameter(java.lang.String param,
java.lang.Object value)
throws java.security.InvalidParameterException
InvalidParameterException.
Use engineSetParameter(AlgorithmParameterSpec) instead.
engineSetParameter in class java.security.SignatureSpiparam - [FIPS 140-2 data input] ignoredvalue - [FIPS 140-2 data input] ignoredjava.security.InvalidParameterException - [FIPS 140-2 status output] always thrown; this method of
setting parameters is not supportedprotected final void engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
throws java.security.InvalidAlgorithmParameterException
IMPORTANT: Following this call, the algorithm must be
initialized before it can be used for signature generation or
verification. This ensures the algorithm is always operating with the
proper parameters. If this procedure is not obeyed, a
SignatureException will result during the signature
generation or verification attempt.
This approach is taken to workaround flaws in Java's Signature architecture; specifically the fact that parameters are not passed in with an initialize call and instead are passed in with a separate set call.
engineSetParameter in class java.security.SignatureSpiparams - [FIPS 140-2 data input] the parametersjava.security.InvalidAlgorithmParameterException - [FIPS 140-2 status output] if the given parameters are
inappropriate for this signature algorithmFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected final java.lang.Object engineGetParameter(java.lang.String param)
throws java.security.InvalidParameterException
InvalidParameterException.
Use engineGetParameters() instead.
engineGetParameter in class java.security.SignatureSpiparam - [FIPS 140-2 data input] ignoredjava.security.InvalidParameterException - [FIPS 140-2 status output] always thrown; this method of
getting parameters is not supportedprotected final java.security.AlgorithmParameters engineGetParameters()
null if this signature algorithm does not use any
parameters.
The returned parameters may be the same that were used to initialize this signature algorithm, or may contain a combination of default and randomly generated parameter values used by the underlying signature implementation if this signature algorithm requires algorithm parameters but was not initialized with any.
engineGetParameters in class java.security.SignatureSpinull if this signature algorithm does
not use any parametersFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationspublic final byte[] getDigest()
ExtendedSignature
During both a signature generation and verification operation a digest is
calculated over the message; this digest is then used as an input to the
signature generation or verification process. This API simply provides
access to the digest once it has been calculated; it always returns the
digest from the last operation. If a signature generation or verification
operation has not yet been executed or is in the process of being
executed, null is returned.
To ensure a non-null result, this method should only be called after
Signature.sign() or Signature.verify() has
called.
getDigest in interface ExtendedSignatureprotected final java.security.SecureRandom getPrng()
throws java.lang.IllegalStateException
If a PRNG was manually specified during initialization, this PRNG is
returned; otherwise an implementation of Entrust's default PRNG is
returned. This can be used in generateDefaultParameters to
provide the source of randomness that may be required during generation
of default algorithm parameters.
java.lang.IllegalStateException - if this method is called prior to initializing the algorithmprotected void assertParametersValid(java.security.spec.AlgorithmParameterSpec params)
throws java.security.InvalidAlgorithmParameterException
This default implementation is only appropriate for algorithms that do
not support algorithm parameters; it throws an
InvalidAlgorithmParameterException indicating that
parameters are not supported when non-null parameters are provided. For
algorithms that do support algorithm parameters, this API must be
overridden to check that the parameters that were passed in are valid and
appropriate for the algorithm.
params - the parametersjava.security.InvalidAlgorithmParameterException - if the given parameters are inappropriate for this signature
algorithmprotected java.security.spec.AlgorithmParameterSpec generateDefaultParameters()
This default implementation is only appropriate for algorithms that do
not support algorithm parameters; it always returns null.
For algorithms that do support algorithm parameters, this API must be
overridden to generate a valid and appropriate set of default algorithm
parameters. These parameters will automatically be used when parameters
are not provided through the engineSetParameter() API and
the algorithm is initialized for signature generation.
null if
this algorithm does not support parametersprotected java.security.AlgorithmParameters toAlgorithmParameters(java.security.spec.AlgorithmParameterSpec params)
engineGetParameters()
.
This default implementation is only appropriate for algorithms that do
not support algorithm parameters; it always returns null.
For algorithms that do support algorithm parameters, this API must be
overridden to convert supported parameters in transparent representation
to opaque representation.
params - a transparent representation of the algorithm parametersnull if this algorithm does not support parametersprotected abstract com.entrust.toolkit.security.crypto.signature.DigitalSignatureImpl getDigitalSignatureImpl(java.lang.String implClassName)
throws java.lang.RuntimeException
This API is necessary so that the signature algorithm implementation classes can exist in a different package and not require public constructors.
implClassName - the name of the class for the signature algorithm
implementationjava.lang.RuntimeException - if the signature algorithm implementation could not be
instantiated