|
|||||||||
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.RawDSA
This class implements the "Raw" DSA signature algorithm. That is, it expects its input to be already hashed with SHA-1.
Use it like any other signature algorithm, but supply the hashed data to
the update()
methods instead of the original data to be signed.
You can call all of the update methods in any combination, but when you
call sign()
or verify()
exactly 20 bytes must have
been passed during the updates. This is necessary because DSA was spefically
designed for the 160 bit hashes of SHA-1.
If you are going to sign some yet not hashed data (respectively verify the
corresponding signature), you can use the DSA
implemetation
which automatically hashes the supplied data according the SHA algorithm
before processing it with the RawDSA algorithm.
The Digital Signature Algorithm (DSA) only can be used for digital signing (respectively signature verifying). It cannot be used for data encryption.
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)
k
, which has to be shorter
than q
. These computations are done using the entities private key and
result in two BigInteger values r
and s
representing the
signature. For verifying a given signature, the signing entity´s public key has to be
used for performing computations on the signature consisting of the two BigIntegers
r
and s
. Beside the common way of signing messages and
verifying signatures (see below) by using the corresponding sign
and
verify
methods, this class is equipped with a set of alternative signing
and verifying methods allowing to handle DSA signatures immediately by their inherent
BigInteger values r
and s
.
For signing some message or verifying a signature using RawDSA, generally an application will have to perform three steps:
getInstance
method, e.g.:
Signature dsa = Signature.getInstance("RawDSA");
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
already hashed 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(hashedData); byte[] signature = dsa.sign();
dsa.update(hashedData); System.out.println("Signature " + (dsa.verify(signature) ? "correct!" : "not correct!"));
DSA
,
SHA
,
Signature
Fields inherited from class java.security.Signature |
SIGN, state, UNINITIALIZED, VERIFY |
Fields inherited from class java.security.SignatureSpi |
appRandom |
Constructor Summary | |
RawDSA()
The default constructor. |
Method Summary | |
BigInteger[] |
dsaSignRS()
Sign method that returns the signature as two BigIntegers. |
boolean |
dsaVerifyRS(BigInteger[] rs)
Verify method that accepts the signature as an array of two BigIntegers. |
boolean |
dsaVerifyRS(BigInteger r,
BigInteger s)
Verify method that accepts the signature as two BigIntegers. |
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 RawDSA 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)
Set 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 hashed 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 RawDSA()
Applications use Signature.getInstance("RawDSA");
for creating a
RawDSA Signature object.
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 the key is improperly
encoded, parameters are missing, and so on.protected void engineUpdate(byte b) throws SignatureException
engineUpdate
in class SignatureSpi
b
- the hash 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 already hashed 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
engineSign
in class SignatureSpi
SignatureException
- if the engine has not been properly initialized.public BigInteger[] dsaSignRS()
This method works exactly like engineSign()
,
but it returns the signature as the two BigIntegers r and s instead of their ASN.1
encoding.
r
at index 0,
and s
at index 1) representing the signatureprotected boolean engineVerify(byte[] sigBytes) throws SignatureException
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.public boolean dsaVerifyRS(BigInteger[] rs)
Index 0 of the array must hold r
, index 1 s
.
rs
- the BigInteger array holding r
at index 0 and s
at index 1true
if the signature is o.k., false
if not.public boolean dsaVerifyRS(BigInteger r, BigInteger s)
r
- the first BigIntegers
- the second BigIntegertrue
if the signature is o.k., false
if not.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.
engineSetParameter
in class SignatureSpi
param
- the name of the parameter ("KSEED")value
- the value of the parameter to be setInvalidParameterException
- if the given parameter name is not "KSEED" or the given
parameter value is not specified as byte array or BigIntegerSignature.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
For security reasons this method will only return a KSEED that was previously set
using engineSetParameter()
,
not an internally generated one while signing.
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)
|
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 |