0703-spring cloud config-git配置属性加解密之对称加密

一、概述

  可以使用{cipher} *格式的加密值,只要有一个有效的密钥,那么它们将在主应用程序上下文获取环境之前被解密。要在应用程序中使用加密功能,您需要在您的类路径中包含Spring Security RSA(Maven协调“org.springframework.security:spring-security-rsa”),并且您还需要JVM中的全功能JCE扩展。

  要使用加密和解密功能,您需要安装在JVM中的全功能JCE(默认情况下不存在此功能)。JRE lib / security目录中的2个策略文件替换

1.1、下载安装

基础:Java Cryptography Extension (JCE) ,下载地址:

下载java 8 jce。

解压安装,按照readme安装。即JRE lib / security目录中的2个策略文件替换

1.2、项目开发

git:

配置文件增加

encrypt:
  key: foobar

启动项目访问使用curl

加密

curl -X POST http://localhost:8080/encrypt foobar

访问后结果:

{"timestamp":1527599182964,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Required request body is missing: public java.lang.String org.springframework.cloud.config.server.encryption.EncryptionController.encrypt(java.lang.String,org.springframework.http.MediaType)","path":"/encrypt"}curl: (6) Could not resolve host: foobar

解密

等等

原文地址:https://www.cnblogs.com/bjlhx/p/9102743.html