com.dstc.security.cms
Class CMSCipher

java.lang.Object
  |
  +--com.dstc.security.cms.CMSCipher

public class CMSCipher
extends Object

A class for encrypting (enveloping) data according to the CMS specification and for decrypting data generated according to that specification.


Constructor Summary
CMSCipher()
          Default constructor
 
Method Summary
 DecryptionResult decrypt()
          Decrypts the previously supplied CMS enveloped data and returns a DecryptionResult instance from which the recovered plaintext data can be read.
 CMSTypedDataInputStream encrypt()
          Encrypts the previously supplied data and returns a CMSTypedDataInputStream from which the CMS enveloped data can be read.
 void initDecrypt(PrivateKey priv, X509Certificate cert)
          Initializes for decryption of one or more instances of CMS enveloped data with a recipient's private key and associated certificate.
 void initEncrypt(SecureRandom rand, X509Certificate[] rcptCerts, String cipherAlg)
          Initializes for encryption of one or more pieces of data with a random number generator together with the content encryption algorithm and a list of recipient certificates.
 void setDataToBeDecrypted(InputStream is)
          Supplies the CMS enveloped data to be decrypted in the form of an InputStream.
 void setDataToBeEncrypted(CMSTypedDataInputStream is)
          Supplies the data to be encrypted (turned into CMS enveloped data) in the form of a CMSTypedDataInputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CMSCipher

public CMSCipher()
Default constructor
Method Detail

initEncrypt

public void initEncrypt(SecureRandom rand,
                        X509Certificate[] rcptCerts,
                        String cipherAlg)
                 throws CMSException
Initializes for encryption of one or more pieces of data with a random number generator together with the content encryption algorithm and a list of recipient certificates. The SecureRandom instance is used to generate session keys and should be carefully seeded. The cipher algorithm can be one of three supported algorithms: DESede, RC2 or RC2/40.

initDecrypt

public void initDecrypt(PrivateKey priv,
                        X509Certificate cert)
                 throws CMSException
Initializes for decryption of one or more instances of CMS enveloped data with a recipient's private key and associated certificate.

setDataToBeEncrypted

public void setDataToBeEncrypted(CMSTypedDataInputStream is)
                          throws CMSException
Supplies the data to be encrypted (turned into CMS enveloped data) in the form of a CMSTypedDataInputStream. The data to be encrypted could itself be signed or enveloped data (for instance, obtained from calling sign() on a CMSSignature), thereby allowing arbitrary nesting of CMS data.

setDataToBeDecrypted

public void setDataToBeDecrypted(InputStream is)
                          throws CMSException
Supplies the CMS enveloped data to be decrypted in the form of an InputStream.

No checks are performed on the supplied InputStream at this point.


encrypt

public CMSTypedDataInputStream encrypt()
                                throws CMSException,
                                       IOException
Encrypts the previously supplied data and returns a CMSTypedDataInputStream from which the CMS enveloped data can be read.

A call to this method resets the state to when initEncrypt() was last called.


decrypt

public DecryptionResult decrypt()
                         throws CMSException,
                                IOException
Decrypts the previously supplied CMS enveloped data and returns a DecryptionResult instance from which the recovered plaintext data can be read.

A call to this method resets the state to when initDecrypt() was last called.