com.github.mowedgrass:jasypt-gradle-boot-encryptor

Shared jasypt encryptor for jasypt-gradle-boot-plugin

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

com.github.mowedgrass
ArtifactId

ArtifactId

jasypt-gradle-boot-encryptor
Last Version

Last Version

0.1.32
Release Date

Release Date

Type

Type

jar
Description

Description

com.github.mowedgrass:jasypt-gradle-boot-encryptor
Shared jasypt encryptor for jasypt-gradle-boot-plugin
Project URL

Project URL

https://github.com/mowedgrass/jasypt-gradle-boot
Source Code Management

Source Code Management

https://github.com/mowedgrass/jasypt-gradle-boot

Download jasypt-gradle-boot-encryptor

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mowedgrass/jasypt-gradle-boot-encryptor/ -->
<dependency>
    <groupId>com.github.mowedgrass</groupId>
    <artifactId>jasypt-gradle-boot-encryptor</artifactId>
    <version>0.1.32</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mowedgrass/jasypt-gradle-boot-encryptor/
implementation 'com.github.mowedgrass:jasypt-gradle-boot-encryptor:0.1.32'
// https://jarcasting.com/artifacts/com.github.mowedgrass/jasypt-gradle-boot-encryptor/
implementation ("com.github.mowedgrass:jasypt-gradle-boot-encryptor:0.1.32")
'com.github.mowedgrass:jasypt-gradle-boot-encryptor:jar:0.1.32'
<dependency org="com.github.mowedgrass" name="jasypt-gradle-boot-encryptor" rev="0.1.32">
  <artifact name="jasypt-gradle-boot-encryptor" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mowedgrass', module='jasypt-gradle-boot-encryptor', version='0.1.32')
)
libraryDependencies += "com.github.mowedgrass" % "jasypt-gradle-boot-encryptor" % "0.1.32"
[com.github.mowedgrass/jasypt-gradle-boot-encryptor "0.1.32"]

Dependencies

compile (1)

Group / Artifact Type Version
com.github.ulisesbocchio : jasypt-spring-boot-starter jar 1.2

Project Modules

There are no modules declared in this project.

jasypt-gradle-boot

Jasypt gradle plugin for Spring Boot. Based on jasypt-spring-boot.

Plugin helps to encrypt sensitive properties and prevents from reading them directly from the source code files. Jasypt decrypts them during runtime.

How to start

Add a buildscript dependency:

buildscript {
 repositories {
     mavenCentral()
 }
 dependencies {
     classpath 'com.github.mowedgrass:jasypt-gradle-boot-plugin:0.1.33'
 }
}

Apply the plugin:

apply plugin: 'encrypt'

Tasks

For all plugin's tasks password can be provided as a command line parameter or as a system environment variable - look below for details.

encryptText

./gradlew encryptText --text <text> [--password <password>]

decryptText

./gradlew decryptText --text <text> [--password <password>]

encryptProperties

./gradlew encryptProperties [--password <password>] [--confirm]

Parses property files (*.properties and *.yml) and encrypts properties marked with ENCRYPT tag. For example property app.secret with value to-be-encrypted marked as:

app.secret=ENCRYPT(to-be-encrypted)

will be encrypted to:

app.secret=ENC(9ERJIetzDhJqIAdS6q7y9N5BtAJlq0KG)

You will be warned if any other properties is encrypted with different password.

Without --confirm parameter task works in a dry-run mode.

During encryption the original file will be backed up to <file>.bak. You will probably want to add this extension to your .gitignore file.

decryptProperties

./gradlew decryptProperties [--password <password>] [--tag] [--confirm]

Parses property files (*.properties and *.yml) and decrypts properties marked with ENC tag. For example property app.secret with encrypted value marked as:

app.secret=ENC(9ERJIetzDhJqIAdS6q7y9N5BtAJlq0KG)

will be decrypted to:

app.secret=to-be-encrypted

or (if --tag parameter is provided) to:

app.secret=ENCRYPT(to-be-encrypted)

You will be warned if any other properties is encrypted with different password.

Without --confirm parameter task works in a dry-run mode.

During decryption the original file will be backed up to <file>.bak. You will probably want to add this extension to your .gitignore file.

Password

Plugin and runtime decryptor uses the first available password source:

  • standard jasypt password property: jasypt.encryptor.password
  • abbreviation of the above: jasypt.password
  • system environment variable: JASYPT_ENCRYPTOR_PASSWORD
  • abbreviation of the above: JASYPT_PASSWORD

There are several ways to pass the password:

  • to jar

    • as an argument:
        java -jar <app.jar> --jasypt.password=<password>
    • as a property:
        java -Djasypt.password=<password> -jar <app.jar>
    • as a system environment property:
        JASYPT_PASSWORD=<password>
        java -jar <app.jar>
  • to gradle task

    • as a property:
        ./gradlew bootRun -Djasypt.password=<password>
    
    • as a system environment property:
        JASYPT_PASSWORD=<password>
        ./gradlew bootRun
        JASYPT_PASSWORD=<password>
        ./gradlew encryptText --text <text>
        JASYPT_PASSWORD=<password>
        ./gradlew decryptProperties

Configuration

Application and gradle plugin uses the same configuration file jasypt.properties (if provided). Look here for details.

Tips

  • keep your default spring profile unencrypted - don't make your life too complicated
  • don't try to use different passwords in related profiles

Demo

Run the default profile:

./gradlew bootRun

Change spring profile and try to run application without password:

SPRING_PROFILES_ACTIVE=production
./gradlew bootRun

Oops, what an ugly exception. Try this:

SPRING_PROFILES_ACTIVE=staging
JASYPT_PASSWORD=simple
./gradlew bootRun

Or this:

SPRING_PROFILES_ACTIVE=production
JASYPT_PASSWORD=qwerty
./gradlew bootRun

Play with decryptProperties and encryptProperties tasks. Notice the warning as a result of different passwords in different profiles/property files.

Versions

Version
0.1.32
0.1.3