Class AesBytesEncryptor
java.lang.Object
org.springframework.security.crypto.encrypt.AesBytesEncryptor
- All Implemented Interfaces:
BytesEncryptor
Encryptor that uses AES encryption.
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionAesBytesEncryptor
(String password, CharSequence salt) Constructs an encryptor that uses AES encryption.AesBytesEncryptor
(String password, CharSequence salt, BytesKeyGenerator ivGenerator) Constructs an encryptor that uses AES encryption.AesBytesEncryptor
(String password, CharSequence salt, BytesKeyGenerator ivGenerator, AesBytesEncryptor.CipherAlgorithm alg) Constructs an encryptor that uses AES encryption.AesBytesEncryptor
(SecretKey secretKey, BytesKeyGenerator ivGenerator, AesBytesEncryptor.CipherAlgorithm alg) Constructs an encryptor that uses AES encryption. -
Method Summary
-
Constructor Details
-
AesBytesEncryptor
Constructs an encryptor that uses AES encryption. Example:AesBytesEncryptor encryptor = new AesBytesEncryptor(yourPassword, 5c0744940b5c369b);
Constructed encryptor uses a 16-byte IV and CBC mode encryption. To specify a custom length IV, useAesBytesEncryptor(String, CharSequence, BytesKeyGenerator)
. To specify both, a custom length IV and a different encryption mode, useAesBytesEncryptor(String, CharSequence, BytesKeyGenerator, CipherAlgorithm)
.- Parameters:
password
- the password valuesalt
- the hex-encoded salt value
-
AesBytesEncryptor
Constructs an encryptor that uses AES encryption. Example:AesBytesEncryptor encryptor = new AesBytesEncryptor(yourPassword, 5c0744940b5c369b, KeyGenerators.secureRandom(16));
Constructed encryptor uses CBC mode encryption. To specify a different encryption mode, useAesBytesEncryptor(String, CharSequence, BytesKeyGenerator, CipherAlgorithm)
.- Parameters:
password
- the password valuesalt
- the hex-encoded salt valueivGenerator
- the generator used to generate the initialization vector
-
AesBytesEncryptor
public AesBytesEncryptor(String password, CharSequence salt, BytesKeyGenerator ivGenerator, AesBytesEncryptor.CipherAlgorithm alg) Constructs an encryptor that uses AES encryption. Example:AesBytesEncryptor encryptor = new AesBytesEncryptor(yourPassword, 5c0744940b5c369b, KeyGenerators.secureRandom(16), CipherAlgorithm.GCM);
- Parameters:
password
- the password valuesalt
- the hex-encoded salt valueivGenerator
- the generator used to generate the initialization vectoralg
- theAesBytesEncryptor.CipherAlgorithm
to be used
-
AesBytesEncryptor
public AesBytesEncryptor(SecretKey secretKey, BytesKeyGenerator ivGenerator, AesBytesEncryptor.CipherAlgorithm alg) Constructs an encryptor that uses AES encryption.- Parameters:
secretKey
- the secret (symmetric) keyivGenerator
- the generator used to generate the initialization vector. If null, then a default algorithm will be used based on the providedAesBytesEncryptor.CipherAlgorithm
alg
- theAesBytesEncryptor.CipherAlgorithm
to be used
-
-
Method Details
-
encrypt
public byte[] encrypt(byte[] bytes) Description copied from interface:BytesEncryptor
Encrypt the byte array.- Specified by:
encrypt
in interfaceBytesEncryptor
-
decrypt
public byte[] decrypt(byte[] encryptedBytes) Description copied from interface:BytesEncryptor
Decrypt the byte array.- Specified by:
decrypt
in interfaceBytesEncryptor
-