我们有一台Pivotal Cloud Foundry服务器,该服务器配置了带有加密密钥的Spring配置服务器。在相应的属性文件中(通过github),我们为一些简单的属性加上了{cipher}前缀,并且能够在应用程序中很好地获得这些值。但是我们最近注意到的挑战是,当我们有一个需要加密的base64数据时,spring加密会在base64数据的末尾截断尾随等号。而且,当我们的应用程序读取此数据时,由于缺少有效的base64(末尾的填充字符(等号)),因此无法解析该数据。我们尝试使用反斜杠转义等号,但仍然没有运气。我们只是看到两个反斜线,所以想知道是否有任何建议可以解决此问题。谢谢!
据我所知,这里的问题似乎与的用法有关curl
。通过运行,我可以复制您看到的问题:
spring decrypt --key @${HOME}/server_rsa_no_eol.key "$(curl -H "Authorization: $(cf oauth-token)" https://config-server.example.com/encrypt -s -d 'VGVzdC0=')"
这用于curl
命中加密端点并获取结果,并立即用解密spring decrypt
。如您所指示,此返回VGVzdC0
。
似乎这是一个卷曲问题,因为我可以在https://httpbin.org/post上发表相同的文章,并且得到相同的结果,VGVzdC0
但不使用=
。
$ curl https://httpbin.org/post --data 'VGVzdC0='
{
...
"form": {
"VGVzdC0": ""
},
...
有效的方法是,如果我对=
字符进行url编码。
$ curl https://httpbin.org/post --data 'VGVzdC0%3D'
{
...
"form": {
"VGVzdC0=": ""
},
...
您也可以使用进行curl
url编码,--data-urlencode
但是有一个陷阱。您必须在值前加上=
。所以这也有效
$ curl https://httpbin.org/post --data-urlencode '=VGVzdC0='
{
"args": {},
"data": "",
"files": {},
"form": {
"VGVzdC0=": ""
},
...
从curl手册页:
--data-urlencode <data>
(HTTP) This posts data, similar to the other -d, --data options with the exception that this performs URL-encoding.
To be CGI-compliant, the <data> part should begin with a name followed by a separator and a content specification. The <data> part can be passed to curl using one of the following
syntaxes:
content
This will make curl URL-encode the content and pass that on. Just be careful so that the content doesn't contain any = or @ symbols, as that will then make the syntax match
one of the other cases below!
=content
This will make curl URL-encode the content and pass that on. The preceding = symbol is not included in the data.
关键是最后一部分=content
。这将使curl url编码内容,并且=
不包含前缀。
如果我在上面重复测试,我将得到预期的结果VGVzdC0=
。
spring decrypt --key @${HOME}/server_rsa_no_eol.key "$(curl -H "Authorization: $(cf oauth-token)" https://config-server.example.com/encrypt -s --data-urlencode '=VGVzdC0=')"
顺便说一句,您还可以选择easy选项并安装Spring Boot CLI + Spring Cloud Extension。然后,您可以spring encrypt --key @${HOME}/server_rsa_no_eol.key 'VGVzdC0='
得到正确的值。这确实意味着您需要在本地计算机上拥有或不拥有密钥的副本。
brew install springboot
spring install org.springframework.cloud:spring-cloud-cli:2.2.1.RELEASE
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句