Skip to content

This library provides easy-to-use integration with Jasypt for encrypting and decrypting properties in your Micronaut applications.

License

Notifications You must be signed in to change notification settings

aprietop/jasypt-micronaut

Repository files navigation

Micronaut Jasypt Library

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.

Features

  • Seamless integration with Micronaut configuration.
  • Encrypt and decrypt properties in application configuration files.

Getting Started

1. Add the Dependency

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'
}

2. Configuration

Configure the library in your application.yml or application.properties file. The essential configuration properties include the encryption password and the algorithm.

application.yml
jasypt:
  encryption:
    password: ${JASYPT_PASSWORD} #env. variabale
application.properties
# env. variabale
jasypt.encryption.password=${JASYPT_PASSWORD} 

3. Usage

Encrypt your sensitive properties using Jasypt CLI or any other method. Encrypted properties should be prefixed with ENC( and suffixed with ).

Example

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==)}

4. Accessing Decrypted Properties

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

Contributions are welcome! Please fork the repository and submit pull requests for any enhancements or bug fixes.

License

This project is licensed under the Apache-2.0 License. See the LICENSE file for details.

About

This library provides easy-to-use integration with Jasypt for encrypting and decrypting properties in your Micronaut applications.

Topics

Resources

License

Stars

Watchers

Forks

Languages