XCMS Toolkit

com.cms.crypto
Class EncryptedDataProcessor

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

public class EncryptedDataProcessor
extends java.lang.Object

Creates EncryptedData objects using a symmetrical encryption algorithm and a secret Content Encryption Key (CEK).

Supports the creation of "detached" EncryptedData, by providing methods to create values of ASN.1 type EncryptedData whose encryptedContentInfo component contains no encrypted content, and to seperately encrypt the content.

Decrypts the encrypted content of values of ASN.1 type EncryptedData, or detached content associated with EncryptedData values.

ASN.1 type EncryptedData is defined in ISO 22895 as:

 EncryptedData ::= SEQUENCE {
   version               CMSVersion,
   encryptedContentInfo  EncryptedContentInfo,
   unprotectedAttrs      [1] IMPLICIT UnprotectedAttributes  OPTIONAL
 }
        
 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 objects --
 }
 
 EncryptedContent ::= OCTET STRING
 

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

Constructor Summary
EncryptedDataProcessor(CMSVersion version, Codec codec)
          Constructor for EncryptedDataProcessor with initialization parameters for the syntax version of ASN.1 type EncryptedData and the ASN.1 encoding rules to be used for encoding and decoding values.
 
Method Summary
 EncryptedData createDetached(ContentType contentType, ContentEncryptionAlgorithmIdentifier algorithm, UnprotectedAttributes unprotectedAttributes)
          Creates a value of ASN.1 type EncryptedData whose encrypted content is "detached", and not present in the value of ASN.1 type EncryptedContentInfo message component.
 byte[] decrypt(byte[] ciphertext, EncryptedData encryptedData, javax.crypto.SecretKey key)
          Decrypts ciphertext associated with a value of ASN.1 type EncryptedData in which the optional encryptedContent component of ASN.1 type EncryptedContentInfois absent in the EncryptedData value, and must be provided by the caller.
 byte[] decrypt(EncryptedData encryptedData, javax.crypto.SecretKey key)
          Decrypts a value of ASN.1 type EncryptedData in which the optional encryptedContent component of ASN.1 type EncryptedContentInfois present in the EncryptedData value.
 EncryptedData encrypt(byte[] content, ContentType contentType, ContentEncryptionAlgorithmIdentifier algorithm, javax.crypto.SecretKey key, UnprotectedAttributes unprotectedAttributes)
          Creates a value of ASN.1 type EncryptedData whose encrypted content is present in the value of its ASN.1 type EncryptedContentInfo message component.
 byte[] encryptDetached(byte[] content, ContentEncryptionAlgorithmIdentifier algorithm, javax.crypto.SecretKey key)
          Encrypts the detached content of a value of ASN.1 type EncryptedData 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

EncryptedDataProcessor

public EncryptedDataProcessor(CMSVersion version,
                              Codec codec)
Constructor for EncryptedDataProcessor with initialization parameters for the syntax version of ASN.1 type EncryptedData and the ASN.1 encoding rules to be used for encoding and decoding values.

Parameters:
version - syntax version of ASN.1 type EncryptedData
codec - ASN.1 encoding rules to be used for encoding and decoding
Method Detail

encrypt

public EncryptedData encrypt(byte[] content,
                             ContentType contentType,
                             ContentEncryptionAlgorithmIdentifier algorithm,
                             javax.crypto.SecretKey key,
                             UnprotectedAttributes unprotectedAttributes)
                      throws CryptoException
Creates a value of ASN.1 type EncryptedData whose encrypted content is present in the value of its ASN.1 type EncryptedContentInfo message component.

Encrypts the data to be encrypted (content) using the encryption algorithm and any associated parameters, and a secret Content Encryption Key (CEK). The content to be encrypted may be ordinary data, or one of the CMS types supported by this toolkit, such as SignedData.

Returns an EncryptedData object that contains the encrypted content.

Parameters:
content - data to be encrypted
contentType - the CMS type of content to be encrypted (Data, NamedKeyEncryptedData, SignedData, etc.)
algorithm - encryption algorithm and any associated parameters
key - secret key compatible with the specified encryption algorithm
unprotectedAttributes - attributes that are not part of the cryptographic message, that get transferred in the message
Returns:
a value of ASN.1 type EncryptedData
Throws:
CryptoException

decrypt

public byte[] decrypt(EncryptedData encryptedData,
                      javax.crypto.SecretKey key)
               throws CryptoException,
                      EncodingException
Decrypts a value of ASN.1 type EncryptedData in which the optional encryptedContent component of ASN.1 type EncryptedContentInfois present in the EncryptedData value.

Parameters:
encryptedData - the CMS type whose encrypted content is to be decrypted
key - the secret key that was employed to encrypt the content
Returns:
the decrypted content or null if the content is not present
Throws:
CryptoException
EncodingException

createDetached

public EncryptedData createDetached(ContentType contentType,
                                    ContentEncryptionAlgorithmIdentifier algorithm,
                                    UnprotectedAttributes unprotectedAttributes)
                             throws CryptoException
Creates a value of ASN.1 type EncryptedData whose encrypted content is "detached", and not present in the value of ASN.1 type EncryptedContentInfo message component.

Parameters:
contentType - the CMS type of content to be encrypted (Data, NamedKeyEncryptedData, DigestedData, etc.)
algorithm - encryption algorithm and any associated parameters
unprotectedAttributes - attributes that are not part of the cryptographic message, that get transferred in the message
Returns:
a value of ASN.1 type EncryptedData that does NOT contain encrypted content
Throws:
CryptoException

encryptDetached

public byte[] encryptDetached(byte[] content,
                              ContentEncryptionAlgorithmIdentifier algorithm,
                              javax.crypto.SecretKey key)
                       throws CryptoException
Encrypts the detached content of a value of ASN.1 type EncryptedData 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.

Parameters:
content - data to be encrypted
algorithm - encryption algorithm and any associated parameters
key - secret key compatible with the specified encryption algorithm
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,
                      EncryptedData encryptedData,
                      javax.crypto.SecretKey key)
               throws CryptoException,
                      EncodingException
Decrypts ciphertext associated with a value of ASN.1 type EncryptedData in which the optional encryptedContent component of ASN.1 type EncryptedContentInfois absent in the EncryptedData value, and must be provided by the caller.

Parameters:
ciphertext - the detached encrypted content
encryptedData - the CMS type whose encrypted content is to be decrypted
key - the secret key that was employed to encrypt the content
Returns:
the decrypted content
Throws:
CryptoException
EncodingException

XCMS Toolkit


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