|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.security.SignatureSpi | +--java.security.Signature | +--iaik.security.dsa.DSA
This class implements the DSS (DSA with SHA-1) signature algorithm as specified in FIPS PUB 186. The Digital Signature Algorithm (DSA) only can be used for digital signing (respectively signature verifying). It cannot be used for data encryption.
NIST´s Digital Signature Standard (DSS) specifies the DSA algorithm as public-key algorithm for being used for digital signing applications. For first calculating a hash value of any data to be signed, the Secure Hash Algorithm is proposed to be used along with the DSA algorithm.
The DSA algorithm uses a certain number of parameters:
p
, which length is a multiple of 64 bits lying between 512 and 1024 bits
q
) of p-1
(h(p-1)/q)(mod p) > 1
g = (h(p-1)/q)(mod p)
x
less than q
y
calculated from y = (gx)(mod p)
This class only adds the functionality of the SHA hash algorithm to the pure
DSA algorithm, which is implemented by the RawDSA
sub-class. An
application wishing to hash the message with the SHA function before signing it,
shall use this class:
An application that already has hashed the data to be signed, may use the raw DSA implementation:Signature dsa = Signature.getInstance("DSA");
Signature raw_dsa = Signature.getInstance("RawDSA");
Generally an application intending to sign some message respectively to verify a signature, has to perform three steps:
getInstance
method, e.g.:Signature dsa = Signature.getInstance("DSA");
dsa.initSign(dsaPrivateKey);
dsa.initVerify(dsaPublicKey);
sign
method returning the signature as DER encoded byte array.
Otherwise, if the Signature object has been initialized for verifying, first the
data to be verified is supplied to the Signature object, and subsequently the
signature is verified by calling the verify
method, supplied with the
DER encoded byte array holding the corresponding signature:
dsa.update(data); byte[] signature = dsa.sign();
dsa.update(data); System.out.println("Signature " + (dsa.verify(signature) ? "correct!" : "not correct!"));
RawDSA
,
SHA
,
Signature
Fields inherited from class java.security.Signature |
SIGN, state, UNINITIALIZED, VERIFY |
Fields inherited from class java.security.SignatureSpi |
appRandom |
Constructor Summary | |
DSA()
The default constructor. |
Method Summary | |
protected Object |
engineGetParameter(String param)
Returns a previously set KSEED parameter as a byte array. |
protected void |
engineInitSign(PrivateKey privateKey)
SPI: Initializes this DSA Signature object with the given DSA private key for going to sign some data. |
protected void |
engineInitVerify(PublicKey publicKey)
SPI: Initializes this DSA Signature object with the given DSA public key for performing a signature verification. |
protected void |
engineSetParameter(AlgorithmParameterSpec params)
Initializes this DSA signature engine with the given parameter set. |
protected void |
engineSetParameter(String param,
Object value)
Sets the KSEED parameter for DSA signing. |
protected byte[] |
engineSign()
SPI: Returns the signature bytes of all the data updated so far. |
protected void |
engineUpdate(byte b)
SPI: Updates the data to be signed or verified with the specified byte. |
protected void |
engineUpdate(byte[] b,
int off,
int len)
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)
SPI: Verifies the passed-in signature. |
Methods inherited from class java.security.Signature |
clone, getAlgorithm, getInstance, getInstance, getParameter, getProvider, initSign, initSign, initVerify, initVerify, setParameter, setParameter, sign, sign, toString, update, update, update, verify |
Methods inherited from class java.security.SignatureSpi |
engineInitSign, engineSign |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public DSA()
RawDSA
and SHA
.
Applications use Signature.getInstance("DSA");
for creating a
DSA Signature object.
RawDSA
,
SHA
,
Signature.getInstance(java.lang.String)
Method Detail |
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException
engineInitVerify
in class SignatureSpi
publicKey
- the DSA public key belonging to the DSA private key that has been used for signingInvalidKeyException
- if a key encoding error occursprotected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException
engineInitSign
in class SignatureSpi
privateKey
- the DSA private key to be used for signing.InvalidKeyException
- if a key encoding error occursprotected void engineUpdate(byte b) throws SignatureException
engineUpdate
in class SignatureSpi
b
- the byte to be used for updating.SignatureException
- if the engine has not been properly initializedprotected void engineUpdate(byte[] b, int off, int len) throws SignatureException
engineUpdate
in class SignatureSpi
b
- the byte array holding the data to be used for this update operation.off
- the offset, indicating the start position within the given byte array.len
- the number of bytes to be obtained from the given byte array, starting at the given position.SignatureException
- if the engine has not been properly initialized.protected byte[] engineSign() throws SignatureException
This method updates the underlying RawDSA with the hashed data and signs
it using the RawDSA engineSign
implementation.
engineSign
in class SignatureSpi
SignatureException
- if the engine has not been properly initialized.RawDSA.engineSign()
protected boolean engineVerify(byte[] sigBytes) throws SignatureException
This method updates the underlying RawDSA with the hashed data and verifies
the given signature using the RawDSA engineVerify
implemetation.
engineVerify
in class SignatureSpi
sigBytes
- the signature bytes to be verified.true
if the signature is o.k., false
if not.SignatureException
- if the engine is not initialized
properly, or the passed-in signature is improperly encoded or
of the wrong type, etc.RawDSA.engineVerify(byte[])
protected void engineSetParameter(String param, Object value) throws InvalidParameterException
The generation of a DSA signature involves a random, secret number k that is usually newly generated for each signature. This method allows you to set this number to a specified value. Use "KSEED" as the name and a byte array or a BigInteger as parameter. Use a null value to unset a previously set seed.
CAUTION: Use of this feature is recommended for testing purposes only.
This method only delegates the given parameter to the underlying RawDSA.
You alternatively may supply a java.security.spec.DSAParameterSpec
parameter identified by name "DSAParameterSpec". This may be useful for
initializing the signature verification in situations where there are no
parameters are included in the subjectPublicKeyInfo field of a
X.509 certificate and therefore have to be supplied by other means.
engineSetParameter
in class SignatureSpi
param
- the name of the parameter ("KSEED") or ("DSAParameterSpec")value
- the value of the parameter to be setInvalidParameterException
- if the given parameter name is not "KSEED" respectively "DSAParameterSpec"
or the given parameter value is not specified as byte array or BigInteger
respectively DSAParameterSpecInstanceRawDSA.engineSetParameter(java.lang.String, java.lang.Object)
,
Signature.setParameter(java.lang.String, java.lang.Object)
protected void engineSetParameter(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException
java.security.spec.DSAParameterSpec
. This method
only can be used with JDK1.2.x. For JDK1.1.x you may use method
engineSetParameter(String param, Object value)
with "DSAParameterSpec"
as name indicating that the supplied value is an instance of
DSAParameterSpec}. This method may be useful for initializing
the signature verification in situations where there are no
parameters are included in the subjectPublicKeyInfo field of a
X.509 certificate and therefore have to be supplied by other means.engineSetParameter
in class SignatureSpi
params
- the parameters as instance of java.security.spec.DSAParameterSpecInvalidAlgorithmParameterException
- if the given parameters
are not supplied as java.security.spec.DSAParameterSpecprotected Object engineGetParameter(String param) throws InvalidParameterException
setParameter()
,
not an internally generated one while signing.
This method only asks the underlying RawDSA for the requested parameter value.engineGetParameter
in class SignatureSpi
param
- the name of the parameter which value is to be obtained ("KSEED")setParameter
InvalidParameterException
- if the given parameter name is not "KSEED"Signature.getParameter(java.lang.String)
,
Signature.setParameter(java.lang.String, java.lang.Object)
,
RawDSA.engineGetParameter(java.lang.String)
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |