org.alfresco.encryption
Class AbstractEncryptor

java.lang.Object
  extended by org.alfresco.encryption.AbstractEncryptor
All Implemented Interfaces:
Encryptor
Direct Known Subclasses:
DefaultEncryptor

public abstract class AbstractEncryptor
extends java.lang.Object
implements Encryptor

Basic support for encryption engines.

Since:
4.0

Field Summary
protected  java.lang.String cipherAlgorithm
           
protected  java.lang.String cipherProvider
           
protected  KeyProvider keyProvider
           
protected static org.apache.commons.logging.Log logger
           
 
Constructor Summary
protected AbstractEncryptor()
          Constructs with defaults
 
Method Summary
 java.security.AlgorithmParameters decodeAlgorithmParameters(byte[] encoded)
          Decodes encoded cipher algorithm parameters
 byte[] decrypt(java.lang.String keyAlias, java.security.AlgorithmParameters params, byte[] input)
          Decrypt some bytes
 java.io.InputStream decrypt(java.lang.String keyAlias, java.security.AlgorithmParameters params, java.io.InputStream input)
          Decrypt an input stream
 java.lang.Object decryptObject(java.lang.String keyAlias, java.security.AlgorithmParameters params, byte[] input)
          Decrypt data as an object
 Pair encrypt(java.lang.String keyAlias, java.security.AlgorithmParameters params, byte[] input)
          Encrypt some bytes
 Pair encryptObject(java.lang.String keyAlias, java.security.AlgorithmParameters params, java.lang.Object input)
          Encrypt an object
protected abstract  javax.crypto.Cipher getCipher(java.lang.String keyAlias, java.security.AlgorithmParameters params, int mode)
          Factory method to be written by implementations to construct and initialize physical ciphering objects.
 java.lang.String getCipherAlgorithm()
           
 java.lang.String getCipherProvider()
           
 KeyProvider getKeyProvider()
           
 void init()
           
protected  void resetCipher()
           
 java.io.Serializable sealObject(java.lang.String keyAlias, java.security.AlgorithmParameters params, java.io.Serializable input)
          Convenience method to seal on object up cryptographically.
 void setCipherAlgorithm(java.lang.String cipherAlgorithm)
           
 void setCipherProvider(java.lang.String cipherProvider)
           
 void setKeyProvider(KeyProvider keyProvider)
           
 java.io.Serializable unsealObject(java.lang.String keyAlias, java.io.Serializable input)
          Convenience method to unseal on object sealed up cryptographically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.alfresco.encryption.Encryptor
keyAvailable
 

Field Detail

logger

protected static final org.apache.commons.logging.Log logger

cipherAlgorithm

protected java.lang.String cipherAlgorithm

cipherProvider

protected java.lang.String cipherProvider

keyProvider

protected KeyProvider keyProvider
Constructor Detail

AbstractEncryptor

protected AbstractEncryptor()
Constructs with defaults

Method Detail

setKeyProvider

public void setKeyProvider(KeyProvider keyProvider)
Parameters:
keyProvider - provides encryption keys based on aliases

getKeyProvider

public KeyProvider getKeyProvider()

init

public void init()

getCipher

protected abstract javax.crypto.Cipher getCipher(java.lang.String keyAlias,
                                                 java.security.AlgorithmParameters params,
                                                 int mode)
Factory method to be written by implementations to construct and initialize physical ciphering objects.

Parameters:
keyAlias - the key alias
params - algorithm-specific parameters
mode - the cipher mode
Returns:

encrypt

public Pair encrypt(java.lang.String keyAlias,
                    java.security.AlgorithmParameters params,
                    byte[] input)
Encrypt some bytes

Specified by:
encrypt in interface Encryptor
Parameters:
keyAlias - the encryption key alias
input - the data to encrypt
Returns:
the encrypted data and parameters used

resetCipher

protected void resetCipher()

decrypt

public byte[] decrypt(java.lang.String keyAlias,
                      java.security.AlgorithmParameters params,
                      byte[] input)
Decrypt some bytes

Specified by:
decrypt in interface Encryptor
Parameters:
keyAlias - the encryption key alias
input - the data to decrypt
Returns:
the unencrypted data

decrypt

public java.io.InputStream decrypt(java.lang.String keyAlias,
                                   java.security.AlgorithmParameters params,
                                   java.io.InputStream input)
Decrypt an input stream

Specified by:
decrypt in interface Encryptor
Parameters:
keyAlias - the encryption key alias
input - the data to decrypt
Returns:
the unencrypted data

encryptObject

public Pair encryptObject(java.lang.String keyAlias,
                          java.security.AlgorithmParameters params,
                          java.lang.Object input)
Encrypt an object

Serializes and encrypts the input data.

Specified by:
encryptObject in interface Encryptor
Parameters:
keyAlias - the encryption key alias
input - the object to write to bytes
Returns:
the encrypted data and parameters used

decryptObject

public java.lang.Object decryptObject(java.lang.String keyAlias,
                                      java.security.AlgorithmParameters params,
                                      byte[] input)
Decrypt data as an object

Decrypts and deserializes the input data

Specified by:
decryptObject in interface Encryptor
Parameters:
keyAlias - the encryption key alias
input - the data to decrypt
Returns:
the unencrypted data deserialized

sealObject

public java.io.Serializable sealObject(java.lang.String keyAlias,
                                       java.security.AlgorithmParameters params,
                                       java.io.Serializable input)
Description copied from interface: Encryptor
Convenience method to seal on object up cryptographically.

Note that the original object may be returned directly if there is no key associated with the alias.

Specified by:
sealObject in interface Encryptor
Parameters:
keyAlias - the encryption key alias
input - the object to encrypt and seal
Returns:
the sealed object that can be decrypted with the original key

unsealObject

public java.io.Serializable unsealObject(java.lang.String keyAlias,
                                         java.io.Serializable input)
                                  throws java.security.InvalidKeyException
Description copied from interface: Encryptor
Convenience method to unseal on object sealed up cryptographically.

Note that the algorithm parameters not provided on the assumption that a symmetric key algorithm is in use - only the key is required for unsealing.

Note that the original object may be returned directly if there is no key associated with the alias or if the input object is not a SealedObject.

Specified by:
unsealObject in interface Encryptor
Parameters:
keyAlias - the encryption key alias
input - the object to decrypt and unseal
Returns:
the original unsealed object that was encrypted with the original key
Throws:
java.security.InvalidKeyException

setCipherAlgorithm

public void setCipherAlgorithm(java.lang.String cipherAlgorithm)

getCipherAlgorithm

public java.lang.String getCipherAlgorithm()

setCipherProvider

public void setCipherProvider(java.lang.String cipherProvider)

getCipherProvider

public java.lang.String getCipherProvider()

decodeAlgorithmParameters

public java.security.AlgorithmParameters decodeAlgorithmParameters(byte[] encoded)
Decodes encoded cipher algorithm parameters

Specified by:
decodeAlgorithmParameters in interface Encryptor
Parameters:
encoded - the encoded cipher algorithm parameters
Returns:
the decoded cipher algorithmParameters


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.