Package org.springframework.security.crypto.encrypt

## 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
`static class` `AesBytesEncryptor.CipherAlgorithm`

### Constructor Summary

Constructors
`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
`byte[]` `decrypt​(byte[] encryptedBytes)` Decrypt the byte array.
`byte[]` `encrypt​(byte[] bytes)` Encrypt the byte array.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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, use `AesBytesEncryptor(String, CharSequence, BytesKeyGenerator)`. To specify both, a custom length IV and a different encryption mode, use `AesBytesEncryptor(String, CharSequence, BytesKeyGenerator, CipherAlgorithm)`.

Parameters:
  `password` - the password value
  `salt` - 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, use `AesBytesEncryptor(String, CharSequence, BytesKeyGenerator, CipherAlgorithm)`.

Parameters:
  `password` - the password value
  `salt` - the hex-encoded salt value
  `ivGenerator` - 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 value
  `salt` - the hex-encoded salt value
  `ivGenerator` - the generator used to generate the initialization vector
  `alg` - the `AesBytesEncryptor.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) key
  `ivGenerator` - the generator used to generate the initialization vector. If null, then a default algorithm will be used based on the provided `AesBytesEncryptor.CipherAlgorithm`
  `alg` - the `AesBytesEncryptor.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 interface `BytesEncryptor`

#### decrypt

    public byte[] decrypt​(byte[] encryptedBytes)

Description copied from interface: `BytesEncryptor`
Decrypt the byte array.

Specified by:
  `decrypt` in interface `BytesEncryptor`