public class RSAISO9796P2Signature extends ISO9796P2Signature
ISO 9796 (2002) Part 2 ("Digital Signature schemes giving message
recovery, Part 2: Integer factorization based mechanisms") specifies
three digital signature schemes S1
,
S2
and
S3
. S1 and S3 are deterministic,
S2 is randomized by a random salt value. ISO 9796-2 recommends to use the randomized
scheme (S2) where possible; and to prefer S3 to S1, which only shall be used if
backwards compatibility to the 1997 version of the ISO 9796-2 standard is required.
This class implements the S1 scheme for the RSA public key system. See RSAISO9796P2S2S3Signature
for the RSA based
implementation of signature schemes S2 and S3.
By default this class uses the SHA-1 digest algorithm for hash calculation, but it
can be used with any alternative hash algorithm for which a MessageDigest
engine is available. If you want to use a different hash algorithm you
will have to specify it by means of a ISO9796P2ParameterSpec
object, e.g.:
// create parameter spec ISO9796P2ParameterSpec paramSpec = new ISO9796P2ParameterSpec(); // set hash engine MessageDigest hashEngine = MessageDigest.getInstance("SHA-224", "IAIK"); int hashLen = 28; paramSpec.setHashEngine(hashEngine, hashLen); // set hash id int hashID = ...; paramSpec.setHashID(hashID); // create Signature engine Signature signatureEngine = Signature.getInstance("RSA-ISO9796-2", "IAIK"); // set hash engine and id as parameter signatureEngine.setParameter(paramSpec);The table below shows the default configuration for this RSA based ISO 9796-2 Signature engine. For each option, the column "changeable" tells you if you can change the corresponding setting with an alternative value, supplied as
ISO9796P2ParameterSpec
.
Value |
Changeable |
|
Hash Algorithm |
SHA-1 |
yes |
Hash ID
| 0x33 |
|
Hash Engine |
iaik.security.md.SHA |
|
Explicit Trailer Field |
true |
|
Alternative Signature Function |
true |
|
SecureRandom |
iaik.security.random.SHA1Random |
When creating a RSA-ISO9796-2 Signature engine for signature scheme S2, you have to specify
"RSA-ISO9796-2" as algorithm name (the "2" in the name indicates the "Part 2" version of
the ISO 9796 Signature standard). Subsequently init the Signature engine with the private
signing or public verification RSA key and then specify the data to be signed/verified through
one or -- if required -- more calls of method update
. Finally create or verify
the signature value by calling method sign
or verify
, respectively, e.g.
(see also demo source of class demo.TestSignature
):
// create Signature engine Signature signatureEngine = Signature.getInstance("RSA-ISO9796-2", "IAIK"); // the private signing key PrivateKey privateKey = ...; signatureEngine.initSign(privateKey); // supply data to be signed by one or more update calls signatureEngine.update(...); ... // create signature byte[] signature = signatureEngine.sign();And on the verification side:
// create Signature engine Signature signatureEngine = Signature.getInstance("RSA-ISO9796-2", "IAIK"); // the public verification key PublicKey publicKey = ...; signatureEngine.initVerify(publicKey); // supply data to be verified by one or more update calls signatureEngine.update(...); ... // verify signature boolean ok = signatureEngine.verify(signature);Since ISO 9796-2 represents a signature algorithm giving message recovery, you may get the
recovered part
of the message after having verified the signature, e.g.:
// get the recovered message: AlgorithmParameters recoveredMessage = (AlgorithmParameters)signatureEngine.getParameters(); byte[] rm = recoveredMessage.getEncoded();The recovered message will be equal to the original message if total recovery has been applied. In this case it is possible to verify the signature without calling method
update
of the
Signature engine at all (see Javadoc of RecoveredMessage
for more information).
This Signature engine also can operate in "raw" mode where the
hash value is calculated outside the engine and specified when
calling method update
. However, when running this
engine in raw mode, you have to specify the total message length
and the recoverable part of the message as RawISO9796P2ParameterSpec
.
Signature
,
ISO9796P2Signature
,
ISO9796P2ParameterSpec
,
RawISO9796P2ParameterSpec
,
RecoveredMessage
,
SHAwithRSAISO9796P2Signature
,
SHA256withRSAISO9796P2Signature
,
SHA384withRSAISO9796P2Signature
,
SHA512withRSAISO9796P2Signature
,
RIPEMD128withRSAISO9796P2Signature
,
RIPEMD160withRSAISO9796P2Signature
,
RSAISO9796P2S2S3Signature
hashEngine_, secureRandom_
Modifier | Constructor and Description |
---|---|
|
RSAISO9796P2Signature()
Default constructor.
|
protected |
RSAISO9796P2Signature(java.lang.String name,
int hLen,
byte hashID)
Creates a RSA ISO 9796-2 Signature object with the given name using the
supplied hash ID and hash length.
|
Modifier and Type | Method and Description |
---|---|
protected void |
engineInitSign(java.security.PrivateKey pk)
SPI: Initializes this Signature object with the given
RSA private key for going to sign some data.
|
protected void |
engineInitSign(java.security.PrivateKey pk,
java.security.SecureRandom random)
SPI: Initializes this Signature object with the given
RSA private key for going to sign some data.
|
protected void |
engineInitVerify(java.security.PublicKey pk)
SPI: Initializes this Signature object with the given
RSA public key for performing a signature verification.
|
protected byte[] |
openSignature(byte[] signature)
Performs the initial signature opening operation (decryption with the RSA
public verification key).
|
protected byte[] |
produceSignature(byte[] toBeSigned)
Performs the final signature production operation (encryption
with the RSA private signing key).
|
calculateCapacity, checkHashEngineName, engineGetParameter, engineGetParameters, engineSetParameter, engineSetParameter, engineSign, engineUpdate, engineUpdate, engineVerify, getSecureRandom, registerHashEngine, reset, setSecureRandom
public RSAISO9796P2Signature()
for instantiating an RSA-ISO9796-2 Signature engine.Signature.getInstance("RSA-ISO9796-2", "IAIK");
Signature.getInstance(java.lang.String)
protected RSAISO9796P2Signature(java.lang.String name, int hLen, byte hashID)
An application shall use
for instantiating an RSA-ISO9796-2 Signature engine.Signature.getInstance("RSA-ISO9796-2", "IAIK");
name
- the name of the signature enginehLen
- the length of the output value of the hash algorithm that is used by this Signature enginehashID
- the identification byte of the hash algorithm in useSignature.getInstance(java.lang.String)
protected void engineInitVerify(java.security.PublicKey pk) throws java.security.InvalidKeyException
engineInitVerify
in class java.security.SignatureSpi
pk
- the RSA public key belonging to the RSA private key that has been used for signing.java.security.InvalidKeyException
- if the supplied key cannot be used for initializing this engineprotected void engineInitSign(java.security.PrivateKey pk) throws java.security.InvalidKeyException
engineInitSign
in class java.security.SignatureSpi
pk
- the RSA private key to be used for signing.java.security.InvalidKeyException
- if the supplied key cannot be used for initializing this engineprotected void engineInitSign(java.security.PrivateKey pk, java.security.SecureRandom random) throws java.security.InvalidKeyException
If a SecureRandom never has been supplied by the application, the signature engine will use a default SecureRandom, if required.
engineInitSign
in class java.security.SignatureSpi
pk
- the RSA private key to be used for signing.random
- the SecureRandom if random numbers are required by the signature enginejava.security.InvalidKeyException
- if the supplied key cannot be used for initializing this engineprotected byte[] produceSignature(byte[] toBeSigned) throws java.security.SignatureException
produceSignature
in class ISO9796P2Signature
toBeSigned
- the ISO 9796-2 prepared message representative to be signedjava.security.SignatureException
- if an error occurs when producing the signature valueprotected byte[] openSignature(byte[] signature) throws java.security.SignatureException
openSignature
in class ISO9796P2Signature
signature
- the signature value to be openedjava.security.SignatureException
- if an error occurs when opening the signature