DsaWithSha1Signature
insteadpublic class EntrustDSA extends java.security.Signature implements ExtendedSignature
The Digital Signature Algorithm (DSA) can be used only for signing and verifying digital signatures it cannot be used for data encryption.
NIST's Digital Signature Standard (DSS) specifies the DSA algorithm as a
public-key algorithm for use by digital signing applications. To calculate a
hash value of the data to be signed, DSS uses the Secure Hash Algorithm (SHA)
with the DSA algorithm. This EntrustDSA class adds the
capability of the SHA hash algorithm to the pure DSA algorithm, which is
implemented by a raw DSA implementation class. Internally, the
EntrustDSA class creates a SHA hash of your data before signing
it.
Generally, an application intending to sign data and to verify signatures has to perform three steps:
getInstance method. For example:
Signature dsa = Signature.getInstance("DSA", "Entrust");
dsa.initSign(dsaPrivateKey);dsa.initVerify(dsaPublicKey);Signature object has been initialized for signing,
the data to be signed is supplied to it and the signature is created by
calling the sign method. This method returns the signature as a
DER-encoded byte array. If the Signature object has been
initialized for verifying, the data to be verified is supplied to the
Signature object, and the signature is verified by calling the
verify method. This method takes the DER-encoded byte array
representing the signature as an argument.dsa.update(data); byte[] signature = dsa.sign();
dsa.update(data);
System.out.println("Signature " + (dsa.verify(signature) ? "correct!" : "not correct!"));
Internally, the DSA algorithm uses the following parameters:
p, whose length is a multiple of 64 bits
lying between 512 and 1024 bitsq) of p-1h less than p-1 such that
(h(p-1)/q)(mod p) > 1g calculated from
g = (h(p-1)/q)(mod p)x less than qy calculated from
y = (gx)(mod p)
p, q, g are made public,
y forms the public key, and x represents the
private key.
The following key types are currently supported:
java.security.interfaces.DSAPublicKey or
java.security.interfaces.DSAPrivateKey.DsaConfinedPrivateKey.TokenDSAPrivateKey
.SHA1,
Signature| Modifier and Type | Class and Description |
|---|---|
static class |
EntrustDSA.Raw
Deprecated.
since 8.0; use
DsaWithNoneSignature
instead |
| Constructor and Description |
|---|
EntrustDSA()
Deprecated.
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
engineGetParameter(java.lang.String param)
Deprecated.
Returns an object for a parameter previously set, given a proper
String parameter. |
protected void |
engineInitSign(java.security.PrivateKey privateKey)
Deprecated.
SPI: Initializes this DSA
Signature object
with the given DSA private key in preparation for signing data. |
protected void |
engineInitVerify(java.security.PublicKey publicKey)
Deprecated.
SPI: Initializes this DSA
Signature object
with the given DSA public key for performing a signature verification. |
protected void |
engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
Deprecated.
Initializes this DSA signature engine with the given parameter set.
|
protected void |
engineSetParameter(java.lang.String param,
java.lang.Object value)
Deprecated.
SPI: Sets the specified algorithm parameter to the
specified value.
|
protected byte[] |
engineSign()
Deprecated.
SPI: Returns the signature bytes of all the data updated
so far.
|
protected void |
engineUpdate(byte b)
Deprecated.
SPI: Updates the data to be signed or verified with the
specified byte.
|
protected void |
engineUpdate(byte[] b,
int off,
int len)
Deprecated.
SPI: Updates the data to be signed or verified with the
specified number of bytes, beginning at the specified offset within the
given byte array.
|
protected boolean |
engineVerify(byte[] sigBytes)
Deprecated.
SPI: Verifies the given signature.
|
byte[] |
getDigest()
Deprecated.
Returns the digest that was calculated during signature generation or
verification.
|
protected static byte[] |
RStoASN1(java.math.BigInteger[] rs)
Deprecated.
Converts the (r,s) signature pair to ASN1.
|
protected static byte[] |
RStoASN1(java.math.BigInteger r,
java.math.BigInteger s)
Deprecated.
Converts the (r,s) signature pair to ASN1.
|
clone, getAlgorithm, getInstance, getInstance, getInstance, getParameter, getParameters, getProvider, initSign, initSign, initVerify, initVerify, setParameter, setParameter, sign, sign, toString, update, update, update, update, verify, verifypublic EntrustDSA()
Creates a new DSA Signature object.
Applications use Signature.getInstance("DSA", "Entrust");
for creating a DSA Signature object.
SHA1,
Signature.getInstance(java.lang.String)protected static byte[] RStoASN1(java.math.BigInteger[] rs)
throws java.security.SignatureException
rs - an array of two BigInteger objects, with rs[0] = r and rs[1] =
s.java.security.SignatureException - if there is an error converting the integers to ASN.1.protected static byte[] RStoASN1(java.math.BigInteger r,
java.math.BigInteger s)
throws java.security.SignatureException
r - The first component of the signature.s - The second component of the signature.java.security.SignatureException - if there is an error converting the integers to ASN.1.protected void engineInitVerify(java.security.PublicKey publicKey)
throws java.security.InvalidKeyException
Signature object
with the given DSA public key for performing a signature verification.
engineInitVerify in class java.security.SignatureSpipublicKey - the DSA public key belonging to the DSA private key used for
signingjava.security.InvalidKeyException - if a key encoding error occursprotected void engineInitSign(java.security.PrivateKey privateKey)
throws java.security.InvalidKeyException
Signature object
with the given DSA private key in preparation for signing data.engineInitSign in class java.security.SignatureSpiprivateKey - the DSA private key to be used for signingjava.security.InvalidKeyException - if a key encoding error occursprotected void engineUpdate(byte b)
throws java.security.SignatureException
This method actually updates the data to be hashed using the SHA algorithm.
engineUpdate in class java.security.SignatureSpib - the byte to be used for updating.java.security.SignatureException - if the engine has not been properly initializedprotected void engineUpdate(byte[] b,
int off,
int len)
throws java.security.SignatureException
This method updates the data to be hashed using the SHA algorithm.
engineUpdate in class java.security.SignatureSpib - the byte array holding the data to be used for this update
operationoff - the offset, indicating the start position within the given
byte arraylen - the number of bytes to be obtained from the given byte array,
starting at the specified positionjava.security.SignatureException - if the engine has not been properly initializedprotected byte[] engineSign()
throws java.security.SignatureException
The signature returned is X.509 (DER)-encoded.
engineSign in class java.security.SignatureSpijava.security.SignatureException - if the engine has not been properly initialized.protected boolean engineVerify(byte[] sigBytes)
throws java.security.SignatureException
The signature bytes are expected to be X.509 (DER)-encoded. The method
updates the underlying DSA implementation class with the hashed data and
verifies the given signature using the its engineVerify
implemetation.
engineVerify in class java.security.SignatureSpisigBytes - the signature bytes to be verifiedtrue if the signature is valid, false
if not.java.security.SignatureException - if the engine is not initialized properly, or the
passed-in signature is improperly encoded or of the wrong
type, etc.engineVerify(byte[])protected void engineSetParameter(java.lang.String param,
java.lang.Object value)
throws java.security.InvalidParameterException
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.
engineSetParameter in class java.security.SignatureSpiparam - the string identifier of the parametervalue - the parameter valuejava.security.InvalidParameterException - 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.protected void engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
throws java.security.InvalidAlgorithmParameterException
The supplied parameter set must be an instance of
java.security.spec.DSAParameterSpec. This method can be used
only with J2SDK1.2 and later. This method may be useful for initializing
the signature verification in situations where there are no parameters
included in the subjectPublicKeyInfo field of an X.509
certificate, and therefore have to be supplied by other means.
engineSetParameter in class java.security.SignatureSpiparams - the parameters as instance of
java.security.spec.DSAParameterSpecjava.security.InvalidAlgorithmParameterException - if the given parameters are not supplied as
java.security.spec.DSAParameterSpecprotected java.lang.Object engineGetParameter(java.lang.String param)
throws java.security.InvalidParameterException
String parameter.
engineGetParameter in class java.security.SignatureSpiparam - the String that identifies the particular
parameterString
.java.security.InvalidParameterException - if the given parameter is not suitablepublic 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 ExtendedSignature