Package org.alfresco.encryption
Class AbstractEncryptor
- java.lang.Object
-
- org.alfresco.encryption.AbstractEncryptor
-
- All Implemented Interfaces:
Encryptor
- Direct Known Subclasses:
DefaultEncryptor
public abstract class AbstractEncryptor extends Object implements Encryptor
Basic support for encryption engines.- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description protected String
cipherAlgorithm
protected String
cipherProvider
protected KeyProvider
keyProvider
protected static org.apache.commons.logging.Log
logger
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractEncryptor()
Constructs with defaults
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description AlgorithmParameters
decodeAlgorithmParameters(byte[] encoded)
Decodes encoded cipher algorithm parametersbyte[]
decrypt(String keyAlias, AlgorithmParameters params, byte[] input)
Decrypt some bytesInputStream
decrypt(String keyAlias, AlgorithmParameters params, InputStream input)
Decrypt an input streamObject
decryptObject(String keyAlias, AlgorithmParameters params, byte[] input)
Decrypt data as an objectPair<byte[],AlgorithmParameters>
encrypt(String keyAlias, AlgorithmParameters params, byte[] input)
Encrypt some bytesPair<byte[],AlgorithmParameters>
encryptObject(String keyAlias, AlgorithmParameters params, Object input)
Encrypt an objectprotected abstract Cipher
getCipher(String keyAlias, AlgorithmParameters params, int mode)
Factory method to be written by implementations to construct and initialize physical ciphering objects.String
getCipherAlgorithm()
String
getCipherProvider()
KeyProvider
getKeyProvider()
void
init()
protected void
resetCipher()
Serializable
sealObject(String keyAlias, AlgorithmParameters params, Serializable input)
Convenience method to seal on object up cryptographically.void
setCipherAlgorithm(String cipherAlgorithm)
void
setCipherProvider(String cipherProvider)
void
setKeyProvider(KeyProvider keyProvider)
Serializable
unsealObject(String keyAlias, 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 String cipherAlgorithm
-
cipherProvider
protected String cipherProvider
-
keyProvider
protected KeyProvider keyProvider
-
-
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 Cipher getCipher(String keyAlias, AlgorithmParameters params, int mode)
Factory method to be written by implementations to construct and initialize physical ciphering objects.- Parameters:
keyAlias
- the key aliasparams
- algorithm-specific parametersmode
- the cipher mode- Returns:
- Cipher
-
encrypt
public Pair<byte[],AlgorithmParameters> encrypt(String keyAlias, AlgorithmParameters params, byte[] input)
Encrypt some bytes
-
resetCipher
protected void resetCipher()
-
decrypt
public byte[] decrypt(String keyAlias, AlgorithmParameters params, byte[] input)
Decrypt some bytes
-
decrypt
public InputStream decrypt(String keyAlias, AlgorithmParameters params, InputStream input)
Decrypt an input stream
-
encryptObject
public Pair<byte[],AlgorithmParameters> encryptObject(String keyAlias, AlgorithmParameters params, Object input)
Encrypt an object Serializes andencrypts
the input data.- Specified by:
encryptObject
in interfaceEncryptor
- Parameters:
keyAlias
- the encryption key aliasinput
- the object to write to bytes- Returns:
- the encrypted data and parameters used
-
decryptObject
public Object decryptObject(String keyAlias, AlgorithmParameters params, byte[] input)
Decrypt data as an objectDecrypts
and deserializes the input data- Specified by:
decryptObject
in interfaceEncryptor
- Parameters:
keyAlias
- the encryption key aliasinput
- the data to decrypt- Returns:
- the unencrypted data deserialized
-
sealObject
public Serializable sealObject(String keyAlias, AlgorithmParameters params, 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 interfaceEncryptor
- Parameters:
keyAlias
- the encryption key aliasinput
- the object to encrypt and seal- Returns:
- the sealed object that can be decrypted with the original key
-
unsealObject
public Serializable unsealObject(String keyAlias, Serializable input) throws 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 aSealedObject
.- Specified by:
unsealObject
in interfaceEncryptor
- Parameters:
keyAlias
- the encryption key aliasinput
- the object to decrypt and unseal- Returns:
- the original unsealed object that was encrypted with the original key
- Throws:
InvalidKeyException
-
setCipherAlgorithm
public void setCipherAlgorithm(String cipherAlgorithm)
-
getCipherAlgorithm
public String getCipherAlgorithm()
-
setCipherProvider
public void setCipherProvider(String cipherProvider)
-
getCipherProvider
public String getCipherProvider()
-
decodeAlgorithmParameters
public AlgorithmParameters decodeAlgorithmParameters(byte[] encoded)
Decodes encoded cipher algorithm parameters- Specified by:
decodeAlgorithmParameters
in interfaceEncryptor
- Parameters:
encoded
- the encoded cipher algorithm parameters- Returns:
- the decoded cipher algorithmParameters
-
-