Package com.ibm.di.security
Class SymmetricCipherCrypto
- java.lang.Object
-
- com.ibm.di.security.SymmetricCipherCrypto
-
- All Implemented Interfaces:
Crypto
public class SymmetricCipherCrypto extends java.lang.Object implements Crypto
Secret key encryption/decryption. This class can work with secret key JCE transformations like the one thatjavax.crypto.Cipher.getInstance
accepts. It supports block ciphers (e.g. AES) in various feedback modes (ECB, CBC, CFB, ...) as well as stream ciphers (e.g. RC4). Objects of this class are thread-safe.- Since:
- 7.0
-
-
Constructor Summary
Constructors Constructor Description SymmetricCipherCrypto(java.lang.String transformation, javax.crypto.SecretKey secretKey, java.security.Provider cryptoProvider)
Initializes the object with the specified parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
decrypt(byte[] encryptedData)
Decrypt data.byte[]
encrypt(byte[] data)
Encrypt data.
-
-
-
Constructor Detail
-
SymmetricCipherCrypto
public SymmetricCipherCrypto(java.lang.String transformation, javax.crypto.SecretKey secretKey, java.security.Provider cryptoProvider) throws java.lang.Exception
Initializes the object with the specified parameters. Calculates the size of the initialization vector needed for the transformation. Accepts an optional Java security provider, which will be used for encryption. If the provider is set to null, the implementation will rely on the provider list configured for the JRE.- Parameters:
transformation
- the name of a secret key transformationsecretKey
- a secret key, suitable for the cipher of the transformationcryptoProvider
- a Java security provider- Throws:
java.lang.Exception
- error by the underlying JCE provider
-
-
Method Detail
-
encrypt
public byte[] encrypt(byte[] data) throws java.lang.Exception
Encrypt data. If the feedback mode of the transformation requires an initialization vector (IV), a random one will be created. This makes the IV non-predictable. The encrypted data is prefixed with the IV (if required) as plaintext (the IV does not need to be kept secret).
-
decrypt
public byte[] decrypt(byte[] encryptedData) throws java.lang.Exception
Decrypt data. If the transformation requires an initialization vector (IV), the IV used for encryption is assumed to be located in the beginning of the input buffer.
-
-