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 javax.crypto.SecretKey
generateKey(int bitLength, java.lang.String algorithm, java.lang.String provider)
Generates a key.protected javax.crypto.Cipher
getCipher()
Returns a newCipher
instance, according to current configurations.protected javax.crypto.Mac
getMac()
Returns a newMac
instance, according to current configurations.void
init(org.w3c.dom.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(org.w3c.dom.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 javax.crypto.SecretKey generateKey(int bitLength, java.lang.String algorithm, java.lang.String provider) throws java.security.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:
java.security.GeneralSecurityException
- Since:
- 5.5.0
-
getCipher
protected javax.crypto.Cipher getCipher() throws java.security.GeneralSecurityException
Returns a newCipher
instance, according to current configurations.- Returns:
- the cipher.
- Throws:
java.security.GeneralSecurityException
- Since:
- 5.5.0
- See Also:
Cipher.getInstance(String, String)
-
getMac
protected javax.crypto.Mac getMac() throws java.security.GeneralSecurityException
Returns a newMac
instance, according to current configurations.- Returns:
- the mac.
- Throws:
java.security.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.
-
-