Class AesBytesEncryptor
- java.lang.Object
-
- org.springframework.security.crypto.encrypt.AesBytesEncryptor
-
- All Implemented Interfaces:
BytesEncryptor
public final class AesBytesEncryptor extends java.lang.Object implements BytesEncryptor
Encryptor that uses AES encryption.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AesBytesEncryptor.CipherAlgorithm
-
Constructor Summary
Constructors Constructor Description AesBytesEncryptor(java.lang.String password, java.lang.CharSequence salt)
Constructs an encryptor that uses AES encryption.AesBytesEncryptor(java.lang.String password, java.lang.CharSequence salt, BytesKeyGenerator ivGenerator)
Constructs an encryptor that uses AES encryption.AesBytesEncryptor(java.lang.String password, java.lang.CharSequence salt, BytesKeyGenerator ivGenerator, AesBytesEncryptor.CipherAlgorithm alg)
Constructs an encryptor that uses AES encryption.AesBytesEncryptor(javax.crypto.SecretKey secretKey, BytesKeyGenerator ivGenerator, AesBytesEncryptor.CipherAlgorithm alg)
Constructs an encryptor that uses AES encryption.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
decrypt(byte[] encryptedBytes)
Decrypt the byte array.byte[]
encrypt(byte[] bytes)
Encrypt the byte array.
-
-
-
Constructor Detail
-
AesBytesEncryptor
public AesBytesEncryptor(java.lang.String password, java.lang.CharSequence salt)
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
public AesBytesEncryptor(java.lang.String password, java.lang.CharSequence salt, BytesKeyGenerator ivGenerator)
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(java.lang.String password, java.lang.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(javax.crypto.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 Detail
-
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
-
-