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 StringcipherAlgorithmprotected StringcipherProviderprotected KeyProviderkeyProviderprotected static org.apache.commons.logging.Loglogger
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractEncryptor()Constructs with defaults
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description AlgorithmParametersdecodeAlgorithmParameters(byte[] encoded)Decodes encoded cipher algorithm parametersbyte[]decrypt(String keyAlias, AlgorithmParameters params, byte[] input)Decrypt some bytesInputStreamdecrypt(String keyAlias, AlgorithmParameters params, InputStream input)Decrypt an input streamObjectdecryptObject(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 CiphergetCipher(String keyAlias, AlgorithmParameters params, int mode)Factory method to be written by implementations to construct and initialize physical ciphering objects.StringgetCipherAlgorithm()StringgetCipherProvider()KeyProvidergetKeyProvider()voidinit()protected voidresetCipher()SerializablesealObject(String keyAlias, AlgorithmParameters params, Serializable input)Convenience method to seal on object up cryptographically.voidsetCipherAlgorithm(String cipherAlgorithm)voidsetCipherProvider(String cipherProvider)voidsetKeyProvider(KeyProvider keyProvider)SerializableunsealObject(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 andencryptsthe input data.- Specified by:
encryptObjectin 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 objectDecryptsand deserializes the input data- Specified by:
decryptObjectin 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:EncryptorConvenience 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:
sealObjectin 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:EncryptorConvenience 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:
unsealObjectin 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:
decodeAlgorithmParametersin interfaceEncryptor- Parameters:
encoded- the encoded cipher algorithm parameters- Returns:
- the decoded cipher algorithmParameters
-
-