XCMS Toolkit

com.cms.crypto
Class ContentCipher

java.lang.Object
  extended by com.cms.crypto.ContentCipher

public class ContentCipher
extends java.lang.Object

Encrypts a plaintext message (the "content") using a specified content encryption algorithm and associated parameters, and a provided secret Content Encryption Key (CEK).

This class supports the creation of "detached" encrypted content through its createDetached(), encryptDetached() and decryptDetached() methods. Detached encrypted content messages are defined in the ISO 22895 Cryptographic syntax schema standard for cryptographic message types EncryptedData, EnvelopedData, and NamedKeyEncryptedData, which all reference ASN.1 type EncryptedContentInfo, whose optional encryptedContent component may be present or absent in a message.

ASN.1 type EncryptedContentInfo is defined in IETF RFC 3852:2004 as:

 EncryptedContentInfo ::= SEQUENCE {
    contentType                 ContentType,
    contentEncryptionAlgorithm  ContentEncryptionAlgorithmIdentifier,
    encryptedContent            [0] IMPLICIT EncryptedContent  OPTIONAL
 }
 
 ContentType ::= CONTENTS.&id({Contents})  -- OBJECT IDENTIFIER
 
 ContentEncryptionAlgorithmIdentifier ::= SEQUENCE {
    algorithm   ALGORITHM.&id({ContentEncryptionAlgorithms}),
    parameters  ALGORITHM.&Type({ContentEncryptionAlgorithms}{@algorithm})  OPTIONAL
 }
 
 ContentEncryptionAlgorithms ALGORITHM ::= {
 
    ...  -- Expect additional content encryption algorithm objects --
 }
 
 EncryptedContent ::= OCTET STRING
 

Version:
1.00 - 2006/02/26
Author:
support@phillipgriffin.com

Constructor Summary
ContentCipher(Codec codec)
          Constructor for ContentCipher with ASN.1 encoding rules parameter.
 
Method Summary
 EncryptedContentInfo createDetached(ContentType contentType, ContentEncryptionAlgorithmIdentifier contentEncryptionAlgorithm)
          Creates a value of ASN.1 type EncryptedContentInfo with the optional encryptedContent component absent, to form a "detached" value for a cryptographic message.
 byte[] decrypt(byte[] ciphertext, EncryptedContentInfo message, javax.crypto.SecretKey key)
          The decryptDetached method ASN.1 decodes a value of ASN.1 type EncryptedContentInfo having "detached" encrypted content and to determine the content encryption algorithm in the contentEncryptionAlgorithm component of this ASN.1 type to use to decrypt the provided ciphertext
 byte[] decrypt(EncryptedContentInfo message, javax.crypto.SecretKey key)
          ASN.1 decodes a value of ASN.1 type EncryptedContentInfo and decrypts the ciphertext in the encryptedContent component of this ASN.1 type.
 EncryptedContentInfo encrypt(byte[] plaintext, ContentType contentType, ContentEncryptionAlgorithmIdentifier contentEncryptionAlgorithm, javax.crypto.SecretKey key)
          Encrypts the plaintext using the specified content encryption algorithm and the provided secret Content Encryption Key CEK), and includes the ciphertext results of encrypting the plaintext in the encryptedContent component of ASN.1 type EncryptedContentInfo.
 byte[] encryptDetached(byte[] content, ContentEncryptionAlgorithmIdentifier contentEncryptionAlgorithm, javax.crypto.SecretKey key)
          Encrypts detached content using the specified content encryption algorithm and the provided secret Content Encryption Key CEK), and returns the ciphertext results of encrypting the content to the caller.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentCipher

public ContentCipher(Codec codec)
Constructor for ContentCipher with ASN.1 encoding rules parameter.

Parameters:
codec - ASN.1 encoding rules
Method Detail

encrypt

public EncryptedContentInfo encrypt(byte[] plaintext,
                                    ContentType contentType,
                                    ContentEncryptionAlgorithmIdentifier contentEncryptionAlgorithm,
                                    javax.crypto.SecretKey key)
                             throws CryptoException
Encrypts the plaintext using the specified content encryption algorithm and the provided secret Content Encryption Key CEK), and includes the ciphertext results of encrypting the plaintext in the encryptedContent component of ASN.1 type EncryptedContentInfo.

Parameters:
plaintext - the content to be encrypted
contentType - content type of the palintext to be encrypted
contentEncryptionAlgorithm - content encryption algorithm identifier
key - Content Encryption Key (CEK)
Returns:
an encoded value of ASN.1 type EncryptedContentInfo containing the ciphertext results of encrypting the provided plaintext using the specified content encryption algorithm and provided Content Encryption Key (CEK)
Throws:
CryptoException

decrypt

public byte[] decrypt(EncryptedContentInfo message,
                      javax.crypto.SecretKey key)
               throws CryptoException
ASN.1 decodes a value of ASN.1 type EncryptedContentInfo and decrypts the ciphertext in the encryptedContent component of this ASN.1 type.

Parameters:
message - a value of ASN.1 type EncryptedContentInfo containing the ciphertext to be decrypted in order to recover the plaintext
key - the secret Content Encryption Key (CEK) used to encrypt the plaintext and to decrypt the ciphertext
Returns:
the plaintext (the decrypted ciphertext)
Throws:
CryptoException

createDetached

public EncryptedContentInfo createDetached(ContentType contentType,
                                           ContentEncryptionAlgorithmIdentifier contentEncryptionAlgorithm)
Creates a value of ASN.1 type EncryptedContentInfo with the optional encryptedContent component absent, to form a "detached" value for a cryptographic message.

Note that to create a value of ASN.1 type EncryptedContentInfo with the encrypted content "detached", this method should be used along with the encryptDetached() method.

Parameters:
contentType - content type of the palintext to be encrypted
contentEncryptionAlgorithm - content encryption algorithm identifier
Returns:
an encoded value of ASN.1 type EncryptedContentInfo with the optional encryptedContent component not present in the message.

encryptDetached

public byte[] encryptDetached(byte[] content,
                              ContentEncryptionAlgorithmIdentifier contentEncryptionAlgorithm,
                              javax.crypto.SecretKey key)
                       throws CryptoException
Encrypts detached content using the specified content encryption algorithm and the provided secret Content Encryption Key CEK), and returns the ciphertext results of encrypting the content to the caller.

Note that to create a value of ASN.1 type EncryptedContentInfo with the encrypted content "detached", this method should be used along with the createDetached() method.

Parameters:
content - the content to be encrypted
contentEncryptionAlgorithm - content encryption algorithm identifier
key - Content Encryption Key (CEK)
Returns:
the ciphertext results of encrypting the provided content using the specified content encryption algorithm and provided Content Encryption Key (CEK)
Throws:
CryptoException

decrypt

public byte[] decrypt(byte[] ciphertext,
                      EncryptedContentInfo message,
                      javax.crypto.SecretKey key)
               throws CryptoException
The decryptDetached method ASN.1 decodes a value of ASN.1 type EncryptedContentInfo having "detached" encrypted content and to determine the content encryption algorithm in the contentEncryptionAlgorithm component of this ASN.1 type to use to decrypt the provided ciphertext

Parameters:
ciphertext - value to be dectrypted
message - a value of ASN.1 type EncryptedContentInfo containing the content encryption algorithm identifier needed to decrypt the "detached" ciphertext in order to recover the plaintext
key - the symmetric Content Encryption Key (CEK) used to encrypt the plaintext and decrypt the ciphertext
Returns:
the plaintext (the decrypted ciphertext)
Throws:
CryptoException

XCMS Toolkit


Copyright © 2005-2006 GRIFFIN Consulting. All Rights Reserved.