首页 > 解决方案 > 无法使用非对称加密解密 Spring Cloud 配置中的配置属性

问题描述

我正在尝试从配置服务器加载解密的配置属性,但失败并出现以下错误:

2018-08-07 09:58:26.534 WARN 20400 --- [nio-8888-exec-3] osccseCipherEnvironmentEncryptor:无法解密密钥:密码(java.lang.IllegalStateException 类:无法从存储区加载密钥:类路径资源 [服务器.jks])

当 server.jks 放置在类路径中时会发生此错误。但是当放置在 C:\drive 位置时,它工作正常。

我的配置服务器 bootstrap.yml:

encrypt:
  key-store:
   # location: file:///C:/keystore/server.jks #using asymmetric encryption
    location: classpath:/server.jks #using asymmetric encryption
    password: springcloudconfig
    alias: testconfigkey
    secret: springcloudconfig       
 # key: springcloudconfig #using symmetric encryption

关于我缺少什么的任何想法?非常感谢您的帮助!Spring Boot:2.0.3 JCE 安装 jre/lib 位置

标签: javaspring-bootencryptionspring-cloud-config

解决方案


我刚刚注意到配置服务器项目中不存在 server.jks 文件。放置文件后,它会正确解密内容。

源代码在 Github 中可用:

https://github.com/sureshpec04/spring-cloud-config-sample


推荐阅读