Class AesCbcBytesEncryptor
java.lang.Object
org.springframework.security.crypto.encrypt.AesCbcBytesEncryptor
- All Implemented Interfaces:
BytesEncryptor
BytesEncryptor that uses 256-bit AES/CBC/PKCS5Padding with a random 16-byte
initialization vector. The IV is prepended to the ciphertext on encrypt and stripped on
decrypt.
Note that CBC mode provides confidentiality but not integrity or authenticity.
Applications that require authenticated encryption should prefer
AesGcmBytesEncryptor. See the
OWASP Cryptographic Storage Cheat Sheet for guidance on choosing a cipher mode.
When key derivation is used via withPassword(String, CharSequence), the key is
derived using PBKDF2WithHmacSHA256 with DEFAULT_PBKDF2_ITERATIONS iterations
per the
OWASP Password Storage Cheat Sheet. Because derivation is intentionally expensive,
the encryptor instance should be created once and reused rather than constructed
per-operation.
- Since:
- 5.7.26
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbyte[]decrypt(byte[] encryptedBytes) Decrypt the byte array.byte[]encrypt(byte[] bytes) Encrypt the byte array.static AesCbcBytesEncryptor.BuilderwithPassword(String password, CharSequence salt) Creates an encryptor that derives its key from the given password and hex-encoded salt using PBKDF2WithHmacSHA1.static AesCbcBytesEncryptor.BuilderwithSecretKey(SecretKey secretKey) Creates an encryptor using the suppliedSecretKey.
-
Method Details
-
withPassword
Creates an encryptor that derives its key from the given password and hex-encoded salt using PBKDF2WithHmacSHA1.- Parameters:
password- the password valuesalt- the hex-encoded salt value
-
withSecretKey
Creates an encryptor using the suppliedSecretKey.- Parameters:
secretKey- the secret (symmetric) key
-
encrypt
public byte[] encrypt(byte[] bytes) Description copied from interface:BytesEncryptorEncrypt the byte array.- Specified by:
encryptin interfaceBytesEncryptor
-
decrypt
public byte[] decrypt(byte[] encryptedBytes) Description copied from interface:BytesEncryptorDecrypt the byte array.- Specified by:
decryptin interfaceBytesEncryptor
-