Class Cryptography
This class provides encryption and decryption functionality using TripleDES algorithm. It supports field-level encryption for entities that extend CryptoState and are marked with the @Encryptable annotation.
Key features include:
- TripleDES encryption/decryption
- Field-level encryption support
- Automatic encryption state management
- Reflection-based field processing
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Beas Solution Team
-
Constructor Summary
ConstructorsConstructorDescriptionCryptography
(String secretKey, String vector) Constructor that initializes the cryptographic ciphers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Decrypts all @Encryptable fields in an object.void
Encrypts all @Encryptable fields in an object.plainDecrypt
(String data) Decrypts an encrypted string.plainEncrypt
(String data) Encrypts a plain text string.Methods inherited from class com.beassolution.rule.crypto.BaseCrypto
throwError, throwError
-
Constructor Details
-
Cryptography
public Cryptography(@Value("${cryptography.key}") String secretKey, @Value("${cryptography.iv}") String vector) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException Constructor that initializes the cryptographic ciphers.This constructor initializes the encryption and decryption ciphers using the provided secret key and initialization vector. The ciphers are configured for TripleDES encryption in CBC mode with PKCS5 padding.
- Parameters:
secretKey
- The secret key for encryption/decryptionvector
- The initialization vector- Throws:
NoSuchPaddingException
- if the padding scheme is not availableNoSuchAlgorithmException
- if the algorithm is not availableInvalidAlgorithmParameterException
- if the parameters are invalidInvalidKeyException
- if the key is invalid
-
-
Method Details
-
encrypt
public void encrypt(Object source) throws UnsupportedEncodingException, InvalidAlgorithmParameterException, InvalidKeyException Encrypts all @Encryptable fields in an object.This method processes all fields marked with @Encryptable annotation in the given object and encrypts their values. The object must extend CryptoState for this operation to work.
- Parameters:
source
- The object to encrypt- Throws:
UnsupportedEncodingException
- if encoding is not supportedInvalidAlgorithmParameterException
- if algorithm parameters are invalidInvalidKeyException
- if the key is invalid
-
plainEncrypt
Encrypts a plain text string.- Parameters:
data
- The plain text to encrypt- Returns:
- Base64 encoded encrypted string
- Throws:
IllegalBlockSizeException
- if the block size is invalidBadPaddingException
- if the padding is invalid
-
decrypt
Decrypts all @Encryptable fields in an object.This method processes all fields marked with @Encryptable annotation in the given object and decrypts their values. The object must extend CryptoState and be in an encrypted state.
- Parameters:
target
- The object to decrypt
-
plainDecrypt
Decrypts an encrypted string.- Parameters:
data
- The Base64 encoded encrypted string- Returns:
- The decrypted plain text
- Throws:
IllegalBlockSizeException
- if the block size is invalidBadPaddingException
- if the padding is invalid
-