Package org.saidone.service.crypto
Class AbstractCryptoService
java.lang.Object
org.saidone.component.BaseComponent
org.saidone.service.crypto.AbstractCryptoService
- All Implemented Interfaces:
CryptoService,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
BcCryptoServiceImpl,JcaCryptoServiceImpl
Base implementation for
CryptoService that provides common
functionality for the concrete encryption services. It offers helper methods
to derive secret keys using PBKDF2, HKDF or Argon2 and defines configuration
beans for the supported key derivation algorithms.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration holder for key derivation settings. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecryptText(String encryptedText) Decrypts a Base64 encoded encrypted text stringprotected org.apache.commons.lang3.tuple.Pair<SecretKeySpec, Integer> deriveSecretKey(Secret secret, String algorithm, byte[] salt) Derives a secret key based on the specified key derivation function (KDF) implementation.encryptText(String text, Secret secret) Encrypts a plain text string and returns a Base64 encoded result.Methods inherited from class org.saidone.component.BaseComponent
init, setApplicationContext, shutDown, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.saidone.service.crypto.CryptoService
decrypt, encrypt
-
Field Details
-
kdf
-
-
Constructor Details
-
AbstractCryptoService
public AbstractCryptoService()
-
-
Method Details
-
deriveSecretKey
protected org.apache.commons.lang3.tuple.Pair<SecretKeySpec,Integer> deriveSecretKey(Secret secret, String algorithm, byte[] salt) Derives a secret key based on the specified key derivation function (KDF) implementation.This method selects the key derivation algorithm implementation configured in
kdfand derives a secret key accordingly. Supported KDF implementations include HKDF, Argon2, and PBKDF2 (default).- Parameters:
secret- the secret fetched from Vaultalgorithm- the name of the cryptographic algorithm for which the secret key is derivedsalt- the salt value used in the key derivation process- Returns:
- a
Paircontaining the derivedSecretKeySpecand anIntegerrepresenting the key version
-
encryptText
Encrypts a plain text string and returns a Base64 encoded result.- Specified by:
encryptTextin interfaceCryptoService- Parameters:
text- The text to encryptsecret- secret material used to derive the encryption key- Returns:
- Base64 encoded encrypted text
-
decryptText
Decrypts a Base64 encoded encrypted text string- Specified by:
decryptTextin interfaceCryptoService- Parameters:
encryptedText- The Base64 encoded encrypted text- Returns:
- Decrypted plain text
-