public class AESWrapEncryption extends Object implements AMEncryption, ConfigurableKey
As the password provided by the ConfigurableKey interface cannot be guaranteed to be of high quality, this
implementation uses PBKDF2KeyDerivation to derive unique keys for each item that is encrypted, using
unique 128-bit random salt. This provides significantly improved security compared to just using the encryption
password directly or deriving a single master encryption key from it, and as a side-effect also regains
unpredictable output from AES KeyWrap as a unique key is used to encrypt each plaintext.
AES KeyWrap (AESKW) is a NIST/FIPS-approved key-wrap algorithm. PBKDF2 with HMAC-SHA1/SHA256/SHA384/SHA512 is a NIST-approved password-based key deriviation function. We use or exceed all current NIST recommendations for parameters to these algorithms. The only non-standard aspect is our use of PKCS#5 padding with AESKW rather than the separate padded variant of AESKW. This is for implementation simplicity given that our supported JREs only provide the non-padded AESKW algorithm and PKCS#5 padding is easier to implement correctly.
| Constructor and Description |
|---|
AESWrapEncryption()
Public default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decrypt(byte[] encData)
Decrypts the data using AESWrap and the configured key.
|
byte[] |
encrypt(byte[] rawData)
Encrypts the data using AESWrap and the configured key.
|
void |
setPassword(String password)
Sets the encryption key from a password.
|
public void setPassword(String password) throws Exception
org.forgerock.openam.encryption.key.salt, org.forgerock.openam.encryption.key.iterations and
org.forgerock.openam.encryption.key.size to set the salt (no default, must be set), number of
iterations (defaults to 250,000) and output key size (defaults to 128-bits, can be 128, 192 or 256).setPassword in interface ConfigurableKeypassword - the password to use to derive the encryption key. Must be ASCII.Exception - if an error occurs when deriving a key from the password.public byte[] encrypt(byte[] rawData)
encrypt in interface AMEncryptionrawData - the data to encrypt.IllegalStateException - if a key has not been configured.RuntimeException - if the data cannot be encrypted for any reason.public byte[] decrypt(byte[] encData)
decrypt in interface AMEncryptionencData - the data to decrypt.IllegalStateException - if a key has not been configured.RuntimeException - if the data cannot be decrypted for any reason.Copyright © 2010–2023 Open Identity Platform Community. All rights reserved.