Package lumis.portal.crypto
Class SymmetricCipher
- java.lang.Object
-
- lumis.portal.crypto.AbstractCipher
-
- lumis.portal.crypto.SymmetricCipher
-
- All Implemented Interfaces:
ICipher
,ICipherSpi
public class SymmetricCipher extends AbstractCipher
Generic cipher implementation, based on symmetric ciphers available in the Java Cryptography Architecture (JCA). Also includes aMac
in the encrypted value for integrity check.Configuration elements:
provider
: may be used to specify a JCA provider for the algortithms.algorithm
: the symmetric cipher algorithm.mode
: the cipher mode.padding
: the padding type.keyGenerationSize
: the size, in bits, of the keys automatically generated for this cipher.mac
: the MAC's algorithm.
- Since:
- 5.5.0
- Version:
- $Revision: 24462 $ $Date: 2021-04-19 11:40:07 -0300 (Mon, 19 Apr 2021) $
- See Also:
javax.crypto
-
-
Constructor Summary
Constructors Constructor Description SymmetricCipher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
decrypt(byte[] encryptedValue)
Decrypts an array of bytes.byte[]
encrypt(byte[] plainText)
Encrypts an array of bytes.protected SecretKey
generateKey(int bitLength, String algorithm, String provider)
Generates a key.protected Cipher
getCipher()
Returns a newCipher
instance, according to current configurations.protected Mac
getMac()
Returns a newMac
instance, according to current configurations.void
init(Node configuration)
This method is called only once and before any other method are called.-
Methods inherited from class lumis.portal.crypto.AbstractCipher
decrypt, encrypt, getStringCharset, getUseURLSafeBase64Variant
-
-
-
-
Method Detail
-
init
public void init(Node configuration) throws PortalException
Description copied from interface:ICipherSpi
This method is called only once and before any other method are called. This allows the cipher to initialize itself and read any custom configuration.- Throws:
PortalException
-
generateKey
protected SecretKey generateKey(int bitLength, String algorithm, String provider) throws GeneralSecurityException
Generates a key.- Parameters:
bitLength
- the length of the key, in bits.algorithm
- the algorithm the key will be used for.provider
- the provider of the algorithm.- Returns:
- the key.
- Throws:
GeneralSecurityException
- Since:
- 5.5.0
-
getCipher
protected Cipher getCipher() throws GeneralSecurityException
Returns a newCipher
instance, according to current configurations.- Returns:
- the cipher.
- Throws:
GeneralSecurityException
- Since:
- 5.5.0
- See Also:
Cipher.getInstance(String, String)
-
getMac
protected Mac getMac() throws GeneralSecurityException
Returns a newMac
instance, according to current configurations.- Returns:
- the mac.
- Throws:
GeneralSecurityException
- Since:
- 5.5.0
- See Also:
Mac.getInstance(String, String)
-
decrypt
public byte[] decrypt(byte[] encryptedValue) throws InvalidEncryptedValueException
Description copied from interface:ICipher
Decrypts an array of bytes.- Parameters:
encryptedValue
- the encrypted value.- Returns:
- the value decrypted.
- Throws:
InvalidEncryptedValueException
- ifvalue
is incompatible with this cipher (probably was not encrypted by it or is corrupted).
-
encrypt
public byte[] encrypt(byte[] plainText)
Description copied from interface:ICipher
Encrypts an array of bytes.- Parameters:
plainText
- the original value.- Returns:
- the encrypted value.
-
-