Class PurposeKeyDerivation
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.PurposeKeyDerivation
Derives, from the key-encryption secret (
KeyEncryptionProperties), a distinct salt and key for each purpose
other than the encryption of signing keys, so no two uses share a key: a key exposed or misused for one purpose
says nothing about the others. The salt of a purpose is the HMAC-SHA256 of the purpose label keyed with the
configured salt; its key is derived from the passphrase and that salt with PBKDF2-HMAC-SHA256. The signing-key
cipher (AesGcmKeyCipher) keeps using the configured salt itself, so the keys already stored still decrypt.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intPBKDF2 iterations; a key is derived once per purpose, when its bean is created.private static final StringAlgorithm that derives the key of a purpose.private static final intSize of a derived key in bits (AES-256 / HMAC-SHA256).private final KeyEncryptionPropertiesThe passphrase and the salt of the key-encryption secret.private static final StringAlgorithm that derives the salt of a purpose. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
SALT_ALGORITHM
Algorithm that derives the salt of a purpose.- See Also:
-
KEY_ALGORITHM
Algorithm that derives the key of a purpose.- See Also:
-
ITERATIONS
private static final int ITERATIONSPBKDF2 iterations; a key is derived once per purpose, when its bean is created.- See Also:
-
KEY_BITS
private static final int KEY_BITSSize of a derived key in bits (AES-256 / HMAC-SHA256).- See Also:
-
properties
The passphrase and the salt of the key-encryption secret.
-
-
Constructor Details
-
PurposeKeyDerivation
public PurposeKeyDerivation()
-
-
Method Details
-
saltFor
Derives the salt of a purpose.- Parameters:
purpose- label of the purpose, for exampletotp-secret.- Returns:
- the salt, hex encoded, as
Encryptors.strongerexpects it.
-
keyFor
Derives the key of a purpose.- Parameters:
purpose- label of the purpose, for exampletrusted-device-cookie.- Returns:
- the 256-bit key.
-