This library provides easy-to-use integration with Jasypt for encrypting and decrypting properties in your Micronaut applications. Inspired by jasypt-spring-boot, this library simplifies the setup and usage of Jasypt in Micronaut projects.
- Seamless integration with Micronaut configuration.
- Encrypt and decrypt properties in application configuration files.
To use the Micronaut Jasypt library, add the following dependency to your build.gradle
file:
dependencies {
implementation 'io.github.aprietop:jasypt-micronaut:1.0.0'
}
Configure the library in your application.yml
or application.properties
file. The essential configuration properties include the encryption password and the algorithm.
jasypt:
encryption:
password: ${JASYPT_PASSWORD} #env. variabale
# env. variabale
jasypt.encryption.password=${JASYPT_PASSWORD}
Encrypt your sensitive properties using Jasypt CLI or any other method. Encrypted properties should be prefixed with ENC(
and suffixed with )
.
Encrypt a property value:
jasypt encrypt input="my-secret-value" password="your-encryption-password"
Output:
ENC(GO9jHf7yVuP4E7oGzQmYkQ==)
Use the encrypted value in your application.yml
or application.properties
:
my:
secret:
property: ${ENC(GO9jHf7yVuP4E7oGzQmYkQ==)}
my.secret.property=${ENC(GO9jHf7yVuP4E7oGzQmYkQ==)}
You can inject and use the decrypted properties in your Micronaut beans just like any other configuration property:
import io.micronaut.context.annotation.Value;
import jakarta.inject.Singleton;
@Singleton
public class MyService {
@Value("${my.secret.property}")
private String secretProperty;
public void printSecret() {
System.out.println("Decrypted property value: " + secretProperty);
}
}
Contributions are welcome! Please fork the repository and submit pull requests for any enhancements or bug fixes.
This project is licensed under the Apache-2.0 License. See the LICENSE file for details.