FileDocCategorySizeDatePackage
RsaMd5Sig.javaAPI DocphoneME MR2 API (J2ME)6341Wed May 02 18:00:00 BST 2007com.sun.midp.crypto

RsaMd5Sig

public final class RsaMd5Sig extends Signature
Implements RSA MD5 Signatures.

Fields Summary
private static final byte[]
PREFIX_MD5
Expected prefix in the decrypted result when MD5 hashing is used with RSA signing. This prefix is followed by the MD5 hash. If you are interested, more details are in the comments around the verify method in X509Certificate.
RSASig
rsaSig
Common signature class.
Constructors Summary
public RsaMd5Sig()
Constructs an RSA signature object that uses MD5 as message digest algorithm.

exception
RuntimeException if MD5 is not available


                             
      
        try {
            rsaSig = new RSASig(PREFIX_MD5, MessageDigest.getInstance("MD5"));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Needed algorithm not available");
        }
    
Methods Summary
public java.lang.StringgetAlgorithm()
Gets the signature algorithm.

return
the algorithmimplemented by this signature object

        return "MD5withRSA";
    
public intgetLength()
Gets the byte-length of the signature.

return
the byte-length of the signature produced by this object

        return rsaSig.getLength();
    
public voidinitSign(PrivateKey theKey)
Initializes the RSASig object with the appropriate Key for signature creation.

param
theKey the key object to use for signing
exception
InvalidKeyException if the key type is inconsistent with the mode or signature implementation.

        rsaSig.initSign(theKey);
    
public voidinitVerify(PublicKey theKey)
Initializes the RSASig object with the appropriate Key for signature verification.

param
theKey the key object to use for verification
exception
InvalidKeyException if the key type is inconsistent with the mode or signature implementation.

        rsaSig.initVerify(theKey);
    
public intsign(byte[] sigBuf, int sigOff, int sigLen)
Generates the signature of all/last input data. A call to this method also resets this signature object to the state it was in when previously initialized via a call to init(). That is, the object is reset and available to sign another message.

param
sigBuf the output buffer to store signature data
param
sigOff starting offset within the output buffer at which to begin signature data
param
sigLen max length the signature can be
return
number of bytes of signature output in sigBuf
exception
SignatureException if the signature algorithm does not pad the message and the message is not block aligned


        return rsaSig.sign(sigBuf, sigOff, sigLen);
    
public voidupdate(byte[] inBuf, int inOff, int inLen)
Accumulates a signature of the input data. When this method is used, temporary storage of intermediate results is required. This method should only be used if all the input data required for the signature is not available in one byte array. The sign() or verify() method is recommended whenever possible.

param
inBuf the input buffer of data to be signed
param
inOff starting offset within the input buffer for data to be signed
param
inLen the byte length of data to be signed
exception
SignatureException if the signature algorithm does not pad the message and the message is not block aligned
see
#verify(byte[], int, int, byte[], int, short)


        rsaSig.update(inBuf, inOff, inLen);
    
public booleanverify(byte[] sigBuf, int sigOff, int sigLen)
Verifies the signature of all/last input data against the passed in signature. A call to this method also resets this signature object to the state it was in when previously initialized via a call to init(). That is, the object is reset and available to verify another message.

param
sigBuf the input buffer containing signature data
param
sigOff starting offset within the sigBuf where signature data begins
param
sigLen byte length of signature data
return
true if signature verifies, false otherwise
exception
SignatureException if the signature algorithm does not pad the message and the message is not block aligned


        return rsaSig.verify(sigBuf, sigOff, sigLen);