spring cloud 配置文件加密解密

1.底包
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-rsa</artifactId>
</dependency>

RsaSecretEncryptor   类 encrypt 和  decrypt


1.生成jks复制到项目的src/main/resources中
 
cmd 到 C:\应用软件\java\jdk1.8.0_111\bin 下执行下面语句

keytool -genkeypair -alias ConfigKey -keyalg RSA -dname "CN=Web Server,OU=Unit,O=Organization,L=City,S=State,C=US" -keypass DvdMpqs7qNBBjK -keystore server.jks -storepass n2Fs5UhddfLEDaZ

enkeypair 生成密钥对
alias 要处理的条目的别名
keyalg 密钥算法名称
keypass   密钥口令
keystore  密钥库名称
storepass 密钥库口令


2.配置文件
encrypt:
  key-store:
    location: classpath:/server.jks   文件路径
    password: n2Fs5UhddfLEDaZ         密钥库口令
    alias: ConfigKey                  要处理的条目的别名
    secret: DvdMpqs7qNBBjK            密钥口令



3.使用:需要加密的信息使用"{cipher}+密文" 替换。

encrypt
 
decrypt

 

 

 
posted @ 2022-10-26 09:11  When?  阅读(470)  评论(0编辑  收藏  举报