Class SymmetricKeyCryptographyService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.security.SymmetricKeyCryptographyService
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,MessageEventGenerator,Service,StateManagedComponent
@ComponentProfile(summary="Encrypts or Decrypts payload using key and initial vector", tag="service,cryptography") public class SymmetricKeyCryptographyService extends ServiceImpIn the adapter configuration file this class is aliased as symmetric-key-cryptography-service which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSymmetricKeyCryptographyService.OpMode
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description SymmetricKeyCryptographyService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseService()voiddoService(AdaptrisMessage msg)Apply the service to the message.java.lang.StringgetAlgorithm()java.lang.StringgetCipherTransformation()DataInputParameter<java.lang.String>getInitialVector()DataInputParameter<java.lang.String>getKey()SymmetricKeyCryptographyService.OpModegetOperationMode()MessageWrapper<java.io.InputStream>getSource()MessageWrapper<java.io.OutputStream>getTarget()protected voidinitService()voidprepare()Prepare for initialisation.voidsetAlgorithm(java.lang.String algorithm)Set the name of the secret-key algorithm.voidsetCipherTransformation(java.lang.String cipherTransformation)Set the cipher transformation to be appliedvoidsetInitialVector(DataInputParameter<java.lang.String> initialVector)Set the initial vector for the algorithmvoidsetKey(DataInputParameter<java.lang.String> key)Set the initial key the servicevoidsetOperationMode(SymmetricKeyCryptographyService.OpMode mode)voidsetSource(MessageWrapper<java.io.InputStream> source)Set the source for the input of the crypto service.voidsetTarget(MessageWrapper<java.io.OutputStream> target)Set the target for the output of the crypto service.SymmetricKeyCryptographyServicewithAlgorithm(java.lang.String algorithm)SymmetricKeyCryptographyServicewithCipherTransformation(java.lang.String cipherTransformation)SymmetricKeyCryptographyServicewithInitialVector(DataInputParameter<java.lang.String> initialVector)SymmetricKeyCryptographyServicewithKey(DataInputParameter<java.lang.String> key)SymmetricKeyCryptographyServicewithSource(MessageWrapper<java.io.InputStream> source)SymmetricKeyCryptographyServicewithTarget(MessageWrapper<java.io.OutputStream> target)-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:ServiceApply the service to the message.
- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions
-
initService
protected void initService() throws CoreException- Specified by:
initServicein classServiceImp- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Throws:
CoreException
-
setAlgorithm
public void setAlgorithm(java.lang.String algorithm)
Set the name of the secret-key algorithm.This value is passed in as one of the parameters to
SecretKeySpec(byte[], String); while it is free text, the correct value will depend on what you have agreed with the remote party and support within your JVM.- Parameters:
algorithm- the name of the secret-key algorithm to be associated with the given key.
-
getAlgorithm
public java.lang.String getAlgorithm()
-
withAlgorithm
public SymmetricKeyCryptographyService withAlgorithm(java.lang.String algorithm)
-
setCipherTransformation
public void setCipherTransformation(java.lang.String cipherTransformation)
Set the cipher transformation to be appliedThis value is passed into
Cipher.getInstance(String); while it is free text, the correct value will depend on what you have agreed with the remote party and support within your JVM.- Parameters:
cipherTransformation- the name of the transformation, e.g.AES/CBC/PKCS5Padding.
-
getCipherTransformation
public java.lang.String getCipherTransformation()
-
withCipherTransformation
public SymmetricKeyCryptographyService withCipherTransformation(java.lang.String cipherTransformation)
-
setInitialVector
public void setInitialVector(DataInputParameter<java.lang.String> initialVector)
Set the initial vector for the algorithmDepending on the algorithm you have chosen, then size of the initial vector will vary. For instance, for AES, it needs to be 16 bytes
- Parameters:
initialVector- the Base64 encoded string of initial vector bytes.
-
getInitialVector
public DataInputParameter<java.lang.String> getInitialVector()
-
withInitialVector
public SymmetricKeyCryptographyService withInitialVector(DataInputParameter<java.lang.String> initialVector)
-
setKey
public void setKey(DataInputParameter<java.lang.String> key)
Set the initial key the serviceDepending on the algorithm you have chosen, then size of the key will vary. For instance, for AES, it needs to be 32 bytes
- Parameters:
key- Base64 encoded string of key bytes.
-
getKey
public DataInputParameter<java.lang.String> getKey()
-
withKey
public SymmetricKeyCryptographyService withKey(DataInputParameter<java.lang.String> key)
-
setOperationMode
public void setOperationMode(SymmetricKeyCryptographyService.OpMode mode)
- Parameters:
mode- the operation mode of the cipher: ENCRYPT or DECRYPT (default: DECRYPT)
-
getOperationMode
public SymmetricKeyCryptographyService.OpMode getOperationMode()
-
getSource
public MessageWrapper<java.io.InputStream> getSource()
-
setSource
public void setSource(MessageWrapper<java.io.InputStream> source)
Set the source for the input of the crypto service.- Parameters:
source- the source.
-
withSource
public SymmetricKeyCryptographyService withSource(MessageWrapper<java.io.InputStream> source)
-
getTarget
public MessageWrapper<java.io.OutputStream> getTarget()
-
setTarget
public void setTarget(MessageWrapper<java.io.OutputStream> target)
Set the target for the output of the crypto service.- Parameters:
target- the target.
-
withTarget
public SymmetricKeyCryptographyService withTarget(MessageWrapper<java.io.OutputStream> target)
-
-