public class Sha224RSASignature extends RSASignature
The PKCS#1v1.5 "SHA224 with RSA" signature algorithm is described in PKCS#1.
An application wishing to sign some message or to verify some signature using the "SHA224 with RSA" algorithm, generally has to perform three steps:
getInstance
method, e.g.
Signature sha_rsa = Signature.getInstance("SHA224withRSA");
sha_rsa.initSign(rsaPrivateKey);
sha_rsa.initVerify(rsaPublicKey);
sign
method returning the signature as 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 byte array holding the corresponding signature value:
sha_rsa.update(data); byte[] signature = sha_rsa.sign();
sha_rsa.update(data); System.out.println("Signature " + (sha_rsa.verify(signature) ? "correct!" : "not correct!"));
SHA224
,
RSASignature
,
Signature
Modifier and Type | Field and Description |
---|---|
protected java.security.MessageDigest |
hash
The MessageDigest engine used to hash the data; supplied with an instance of the desired MessageDigest
algorithm by any extending subclass.
|
Constructor and Description |
---|
Sha224RSASignature()
Default Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
engineGetParameter(java.lang.String param)
This method is not used and only throws an InvalidParameterException.
|
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 void |
engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
Allows to supply a SecureRandom object if required by the underlying signature scheme
(e.g.
|
protected void |
engineSetParameter(java.lang.String param,
java.lang.Object value)
Allows to supply a SecureRandom object if required by the underlying signature scheme
(e.g.
|
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.
|
engineSign, engineVerify
protected java.security.MessageDigest hash
public Sha224RSASignature()
Applications do not call this constructor. They shall use one of the
getInstance
methods of the java.security.Signature
class:
Signature sig = Signature.getInstance("SHA224withRSA");
Signature.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 a key encoding error occursprotected 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 a key encoding error occursprotected 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 engine (e.g. PSS)java.security.InvalidKeyException
- if a key encoding error occursprotected void engineUpdate(byte b)
engineUpdate
in class java.security.SignatureSpi
b
- the byte to be used for updating.protected void engineUpdate(byte[] b, int off, int len)
engineUpdate
in class java.security.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.protected void engineSetParameter(java.lang.String param, java.lang.Object value) throws java.security.InvalidParameterException
initSign(PrivateKey, SecureRandom)
is not available. If required by the underlying signature scheme (e.g. PSS) an
application may supply a SecureRandom object as parameter
.
If a SecureRandom never has been supplied by the application, the signature engine will use
a default SecureRandom, if required.engineSetParameter
in class java.security.SignatureSpi
param
- ignoredvalue
- the SecureRandom supplied as PKCS1AlgorithmParameterSpecjava.security.InvalidParameterException
- if the SecureRandom is not supplied as PKCS1AlgorithmParameterSpecprotected void engineSetParameter(java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidAlgorithmParameterException
initSign(PrivateKey, SecureRandom)
to supply a SecureRandom object if required.
If a SecureRandom never has been supplied by the application, the signature engine will use
a default SecureRandom, if required.engineSetParameter
in class java.security.SignatureSpi
params
- the SecureRandom supplied as PKCS1AlgorithmParameterSpecjava.security.InvalidParameterException
- if the SecureRandom is not supplied as PKCS1AlgorithmParameterSpecjava.security.InvalidAlgorithmParameterException
protected java.lang.Object engineGetParameter(java.lang.String param) throws java.security.InvalidParameterException
engineGetParameter
in class java.security.SignatureSpi
java.security.InvalidParameterException
- This Method is not supported