public class SSLRSASignature
extends java.security.SignatureSpi
This class implements a special form of a RSA Signature as used within the Secure Sockets Layer (SSL v3.0) protocol.
SSL handles digital signatures by either using the Digital Signature Algorithm (DSA) or a RSA based method. This class implements the RSA version od SSL digital signing, where the SHA and MD5 hash algorithms are used to form 36-byte structure, which subsequently is signed (encrypted with the RSA private key).
In contrast to Md5RSASignature
and ShaRSASignature
this class not only calls the superclass constructor specifying the hash
algorithm to be used. This class overrides all the methods of the superclass
according to the particular signature requirements of the SSLv3 protocol.
The general proceeding for signing a message (e.g. build up of
client_hello_random + server_hello_random + params
) or verifying
a signature follows the common guidelines prescribing three steps
to be performed:
getInstance
method, e.g.:
Signature ssl_rsa = Signature.getInstance("SSL/RSA");
ssl_rsa.initSign(rsaPrivateKey);
ssl_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:
ssl_rsa.update(data); byte[] signature = ssl_rsa.sign();
ssl_rsa.update(data); System.out.println("Signature " + (ssl_rsa.verify(signature) ? "correct!" : "not correct!"));
RSASignature
,
ShaRSASignature
,
Md5RSASignature
,
Signature
,
Md5
,
SHA
Constructor and Description |
---|
SSLRSASignature()
The default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
engineGetParameter(java.lang.String param)
This method is not implemented and only throws an InvalidParameterException
|
protected void |
engineInitSign(java.security.PrivateKey privateKey)
SPI: Initializes this Signature object with the given
RSA private key for going to sign some data.
|
protected void |
engineInitSign(java.security.PrivateKey privateKey,
java.security.SecureRandom random)
SPI: Initializes this Signature object with the given RSA private
key and the given SecureRandom generator 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.lang.String param,
java.lang.Object value)
This method is not implemented and only throws an InvalidParameterException
|
protected byte[] |
engineSign()
SPI: Returns a byte array holding the signature resulting from
all already performed data update operations.
|
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)
Verifies the given signature of a message according to SSL v3.0.
|
public SSLRSASignature() throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException
- if there is no implementation for MD5 or SHAprotected 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 privateKey) throws java.security.InvalidKeyException
engineInitSign
in class java.security.SignatureSpi
privateKey
- the RSA private key to be used for signing.java.security.InvalidKeyException
- if a key encoding error occursprotected void engineInitSign(java.security.PrivateKey privateKey, java.security.SecureRandom random) throws java.security.InvalidKeyException
engineInitSign
in class java.security.SignatureSpi
privateKey
- the RSA private key to be used for signing.random
- the random number generatorjava.security.InvalidKeyException
- if a key decoding error occursprotected byte[] engineSign() throws java.security.SignatureException
According to SSLv3 the data is digested with both Md5 and SHA algorithms before encrypting the result using the RSA algorithm with PKCS#1 padding.
engineSign
in class java.security.SignatureSpi
java.security.SignatureException
- if an error occurs when creating the signatureprotected boolean engineVerify(byte[] sigBytes) throws java.security.SignatureException
According to SSLv3 the data is digested with both Md5 and SHA algorithms before decrypting it using the RSA algorithm.
engineVerify
in class java.security.SignatureSpi
sigBytes
- the signature bytes to be verifiedtrue
if signature is OK, false
if notjava.security.SignatureException
- if an error occurs when verifying the signatureprotected void engineUpdate(byte b)
engineUpdate
in class java.security.SignatureSpi
b
- the byte to update.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
engineSetParameter
in class java.security.SignatureSpi
java.security.InvalidParameterException
- This Method is not supportedprotected 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