属性加密

David 2022-09-28 23:19:22
Categories: Tags:

 

 

<dependency>

  <groupId>com.github.ulisesbocchio</groupId>

  <artifactId>jasypt-spring-boot-starter</artifactId>

  <version>2.1.0</version>

</dependency>

 

application.author=ENC(9afnWGGYyzZN38vYYfYx1ZM9ql//Vp+8)

 

java -jar foo.jar -Djasypt.encryptor.password=HelloWorld

 

 

 

密钥配置

 

 

 

 

 

生成加密密文

使用工具生成

Jasypt官方提供了CLI工具,通过脚本可以生成对应的密文

Github下载Jasypthttps://github.com/jasypt/jasypt

 

解压进入/bin目录,根据需要执行对应脚本,默认使用PBEWithMD5AndDES算法

示例

$ sh encrypt.sh input=sevenlin password=HelloWorld

 

----ENVIRONMENT-----------------

 

Runtime: Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.73-b02

 

 

----ARGUMENTS-------------------

 

input: sevenlin

 

password: HelloWorld

 

 

----OUTPUT----------------------

 

lUmhU/2EgreTZVdtWFCnqE86tXuo6OMp

 

使用代码生成

public class EncryptDemo {

    public static void main(String[] args) {

        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();

        encryptor.setPassword("HelloWorld");

        String enc = encryptor.encrypt("sevenlin");

        System.out.println(enc);

    }

}

 

 

来自< https://www.jianshu.com/p/b65d93e89b40>