ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.87k stars 514 forks source link

Not able to encrypt #353

Open RezaS opened 1 year ago

RezaS commented 1 year ago

I want to encrypt my email and password:

spring:
  mail:
    host: smtp.gmail.com
    port: 587
    username: ENC(name@gmail.com)
    password: ENC(my-password)
jasypt:
  encryptor:
    password: myPw

When using jasypt:encrypt, I get this error:

[ERROR] Failed to execute goal com.github.ulisesbocchio:jasypt-maven-plugin:3.0.5:encrypt (default-cli) on project Spring_Security: Error Encrypting: Unable to read file src\main\resources\application.properties

In my case, the file application.properties does not exist. Instead, I am using application.yml. So I have tried it this way:

mvn jasypt:encrypt -Djasypt.plugin.path="file:src/main/resources/application.yml" -Djasypt.encryptor.password="myPw"

but then I get the error:

[ERROR] No plugin found for prefix '.plugin.path=file' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\rcie.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]

I have also tried it without file, like this:

mvn jasypt:encrypt -Djasypt.plugin.path="src/main/resources/application.yml" -Djasypt.encryptor.password="myPw"

But then I get this error

[ERROR] Unknown lifecycle phase ".plugin.path=src/main/resources/application.yml". You must specify a valid lifecycle phase or a goal in the format : or :[:]:

. Available lifecycle phases are: pre-clean, clean, post-clean, validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sour ces, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy. -> [Help 1]
awarewire commented 1 year ago

I had the same problem and added this plugin to my file by. Now I had to change version and it worked.

            <plugin>
                <groupId>com.github.ulisesbocchio</groupId>
                <artifactId>jasypt-maven-plugin</artifactId>
                <version>3.0.3</version>
            </plugin>
awarewire commented 1 year ago

/ /

I want to encrypt my email and password:

spring:
  mail:
    host: smtp.gmail.com
    port: 587
    username: ENC(name@gmail.com)
    password: ENC(my-password)
jasypt:
  encryptor:
    password: myPw

When using jasypt:encrypt, I get this error:

[ERROR] Failed to execute goal com.github.ulisesbocchio:jasypt-maven-plugin:3.0.5:encrypt (default-cli) on project Spring_Security: Error Encrypting: Unable to read file src\main\resources\application.properties

In my case, the file application.properties does not exist. Instead, I am using application.yml. So I have tried it this way:

mvn jasypt:encrypt -Djasypt.plugin.path="file:src/main/resources/application.yml" -Djasypt.encryptor.password="myPw"

but then I get the error:

[ERROR] No plugin found for prefix '.plugin.path=file' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\rcie.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]

I have also tried it without file, like this:

mvn jasypt:encrypt -Djasypt.plugin.path="src/main/resources/application.yml" -Djasypt.encryptor.password="myPw"

But then I get this error

[ERROR] Unknown lifecycle phase ".plugin.path=src/main/resources/application.yml". You must specify a valid lifecycle phase or a goal in the format : or :[:]: . Available lifecycle phases are: pre-clean, clean, post-clean, validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sour ces, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy. -> [Help 1]

I had the same problem and added this plugin to my file by. Now I had to change version and it worked.

            <plugin>
                <groupId>com.github.ulisesbocchio</groupId>
                <artifactId>jasypt-maven-plugin</artifactId>
                <version>3.0.3</version>
            </plugin>
awarewire commented 1 year ago

For the new version I found a solution and that is to add the key value in your environment variables and leave it in your properties or yml file. For example

jasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD}
JanCooper commented 6 months ago

I'm using version 3.0.5 and getting the same error. Adding the encryption key to environment variables didn't help.

My command: mvn jasypt:encrypt -Djasypt.plugin.path="file:src/main/resources/application.yml" -Djasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD}

I've tried it both with actual key and environment variable. -Djasypt. is always greyed out, and that's what it seems to be missing.

JanCooper commented 6 months ago

Figured out my issue was, when opening a Windows Terminal, it automatically started with a PowerShell command line. Once I changed it to cmd, everything worked properly.