이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 49. Jasypt
Since Camel 2.5
Jasypt is a simplified encryption library which makes encryption and decryption easy. Camel integrates with Jasypt to allow sensitive information in Properties files to be encrypted. By dropping camel-jasypt on the classpath those encrypted values will automatically be decrypted on-the-fly by Camel. This ensures that human eyes can’t easily spot sensitive information such as usernames and passwords.
49.1. Dependencies 링크 복사링크가 클립보드에 복사되었습니다!
When using camel-jasypt with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jasypt-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jasypt-starter</artifactId>
</dependency>
49.2. Tooling 링크 복사링크가 클립보드에 복사되었습니다!
The Jasypt component is a runnable JAR that provides a command line utility to encrypt or decrypt values. The usage documentation can be output to the console to describe the syntax and options it provides:
A simple way of running the tool is with JBang. For example, to encrypt the value tiger, you can use the following parameters. Make sure to specify the version of camel-jasypt that you want to use.
jbang org.apache.camel:camel-jasypt:<camel version here> -c encrypt -p secret -i tiger
$ jbang org.apache.camel:camel-jasypt:<camel version here> -c encrypt -p secret -i tiger
Which outputs the following result
Encrypted text: qaEEacuW7BUti8LcMgyjKw==
Encrypted text: qaEEacuW7BUti8LcMgyjKw==
This means the encrypted representation qaEEacuW7BUti8LcMgyjKw== can be decrypted back to tiger if you know the master password which was secret.
If you run the tool again then the encrypted value will return a different result. But decrypting the value will always return the correct original value.
You can test decrypting the value by running the tooling using the following parameters:
jbang org.apache.camel:camel-jasypt:<camel version here> -c decrypt -p secret -i qaEEacuW7BUti8LcMgyjKw==
$ jbang org.apache.camel:camel-jasypt:<camel version here> -c decrypt -p secret -i qaEEacuW7BUti8LcMgyjKw==
Which outputs the following result:
Decrypted text: tiger
Decrypted text: tiger
The idea is then to use those encrypted values in your Properties files. For example,
Encrypted value for 'tiger'
# Encrypted value for 'tiger'
my.secret = ENC(qaEEacuW7BUti8LcMgyjKw==)
49.3. Protecting the master password 링크 복사링크가 클립보드에 복사되었습니다!
The master password used by Jasypt must be provided, so that it’s capable of decrypting the values. However, having this master password out in the open may not be an ideal solution. Therefore, you could for example provide it as a JVM system property or as an OS environment setting. If you decide to do so then the password option supports prefixes that dictates this.
-
sysenv:means to lookup the OS system environment with the given key. -
sys:means to lookup a JVM system property.
For example, you could provide the password before you start the application
export CAMEL_ENCRYPTION_PASSWORD=secret
$ export CAMEL_ENCRYPTION_PASSWORD=secret
Then start the application, such as running the start script.
When the application is up and running you can unset the environment
unset CAMEL_ENCRYPTION_PASSWORD
$ unset CAMEL_ENCRYPTION_PASSWORD
On runtimes like Spring Boot and Quarkus, you can configure a password property in the application.properties file as follows.
password=sysenv:CAMEL_ENCRYPTION_PASSWORD
password=sysenv:CAMEL_ENCRYPTION_PASSWORD
Or if configuring JasyptPropertiesParser manually, you can set the password like this.
jasyptPropertiesParser.setPassword("sysenv:CAMEL_ENCRYPTION_PASSWORD");
jasyptPropertiesParser.setPassword("sysenv:CAMEL_ENCRYPTION_PASSWORD");
49.4. Example with Java DSL 링크 복사링크가 클립보드에 복사되었습니다!
On the Spring Boot and Quarkus runtimes, Camel Jasypt can be configured via configuration properties. Refer to their respective documentation pages for more information.
In Java DSL you need to configure Jasypt as a JasyptPropertiesParser instance and set the properties in the Properties component as shown below:
It is possible to configure custom algorithms on the JasyptPropertiesParser like this.
JasyptPropertiesParser jasyptPropertiesParser = new JasyptPropertiesParser();
jasyptPropertiesParser.setAlgorithm("PBEWithHmacSHA256AndAES_256");
jasyptPropertiesParser.setRandomSaltGeneratorAlgorithm("PKCS11");
jasyptPropertiesParser.setRandomIvGeneratorAlgorithm("PKCS11");
JasyptPropertiesParser jasyptPropertiesParser = new JasyptPropertiesParser();
jasyptPropertiesParser.setAlgorithm("PBEWithHmacSHA256AndAES_256");
jasyptPropertiesParser.setRandomSaltGeneratorAlgorithm("PKCS11");
jasyptPropertiesParser.setRandomIvGeneratorAlgorithm("PKCS11");
The properties file secret.properties will contain your encrypted configuration values, such as shown below. Notice how the password value is encrypted and is surrounded like ENC(value here).
my.secret.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)
my.secret.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)
49.5. Example with Spring XML 링크 복사링크가 클립보드에 복사되었습니다!
In Spring XML you need to configure the JasyptPropertiesParser which is shown below. Then the Camel Properties component is told to use jasypt as the properties parser, which means Jasypt has its chance to decrypt values looked up in the properties.
The Properties component can also be inlined inside the <camelContext> tag which is shown below. Notice how we use the propertiesParserRef attribute to refer to Jasypt.
49.6. Spring Boot Auto-Configuration 링크 복사링크가 클립보드에 복사되었습니다!
The component supports 8 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
| camel.component.jasypt.algorithm | The algorithm to be used for decryption. | PBEWithMD5AndDES | String |
| camel.component.jasypt.enabled | Enable the component. | false | Boolean |
| camel.component.jasypt.iv-generator-class-name | The initialization vector (IV) generator applied in decryption operations. Default: org.jasypt.iv. | String | |
| camel.component.jasypt.password | The master password used by Jasypt for decrypting the values. This option supports prefixes which influence the master password lookup behaviour: sysenv: means to lookup the OS system environment with the given key. sys: means to lookup a JVM system property. | String | |
| camel.component.jasypt.provider-name | The class name of the security provider to be used for obtaining the encryption algorithm. | String | |
| camel.component.jasypt.random-iv-generator-algorithm | The algorithm for the random iv generator. | SHA1PRNG | String |
| camel.component.jasypt.random-salt-generator-algorithm | The algorithm for the salt generator. | SHA1PRNG | String |
| camel.component.jasypt.salt-generator-class-name | The salt generator applied in decryption operations. Default: org.jasypt.salt.RandomSaltGenerator. | org.jasypt.salt.RandomSaltGenerator | String |
4.0// ParentAssemblies: assemblies/