我需要在YAML文件中存储一个RSA密钥对,但是对yaml语法的理解仍然有限且缺乏示例让我寻找答案。
我将开始使用我所拥有的东西,但我想知道是否有人能够快速而简洁地解释如何在yaml中存储这种性质的东西。
答案 0 :(得分:13)
您可以将密钥存储为文本(“ASCII-armored”/ base 64编码)。 From Wikipedia,YAML中多行字符串的语法是:
- title: An example multi-line string in YAML
body : |
This is a multi-line string.
"special" metacharacters may
appear here. The extent of this string is
indicated by indentation.
答案 1 :(得分:5)
截至2016年10月27日,这是Google搜索" yaml rsa key"时的第一个结果,所以我想在Yaml中为RSA密钥所需的特定语法添加答案
如果在yaml文件中将密钥包含在一行中,则没有问题。如果您想将它拆分为不同的行以便于阅读,并且无法接受生成的字符串中的换行符,则唯一的选项似乎是带有转义码的双引号。
就我而言,我需要一个生成的单行无空格字符串,因为模板引擎正在使用键定义将键插入到脚本变量中。以下语法将连接每一行没有空格(请注意每行上的' \'以删除换行符):
yourKey: "-----BEGIN PUBLIC KEY-----\
xxx...\
yyy...\
zzz...\
-----END PUBLIC KEY-----"
result: "-----BEGIN PUBLIC KEY-----xxx...yyy...zzz...-----END PUBLIC KEY-----"
可以在SO上找到关于文字格式的非常好的参考:https://stackoverflow.com/a/21699210/4228798
答案 2 :(得分:1)
您可以在yaml文件中添加ssh密钥,如下所示-
---
ssh-key: |-
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEAssBRe91wZ0TJBIWK2V1NH/ourcFPb0cA4ln32a3j5QITMS3zhs/o
euh8jPJ9eca93B+mfep5ly/UjwmDctGbwX54sJngE4Vuv5FgqctR8oHTxV+V18UdolBSsy
yiAVycGUexN2yz7P5JBzwfOG3WEwNe4dNVzmFj51nXAlaX+MB+wLfrZfU1vQpqmU8Esiu+
Hdab948qhmGlMepBw+M4Z7wVfgfz855ywxgL3NrVk2WhXxE9ng/jTLjHKk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8d6
2LwHQJ/fjwDcrMYwEUwDkNoZjhEmj1e5LVTLjRS02VBgjg7RnphpuaphPZ+CDNlq3Om5C9
xW96+4eC9/T7SRaspF3FxhgtPUMI1beu1QnpL0jduT/GQSqaMAAACBAMWR+CLktU6cTBH7
RnfnB2K7E8slA8/hSGUZJ35JXJj5XujQgaf2d8hi4Lmt8smBojaERlCxxx3B9hWVYRkwCM
C8YRNCLnBgR2CCp27D0wuadL9aFITlx91GPytF9BKxzy949VaF6SEw9M86oouj362u/BvP
CO7Hnjlg77HRNFXPAAAAFWxrYW1pcmVkZHlAdm13YXJlLmNvbQECAwQF
-----END OPENSSH PRIVATE KEY-----
请注意,SSH密钥缩进了一个级别。
答案 3 :(得分:0)
通过创建pem文件将密钥存储在yaml文件中是一个好习惯
security:
publickeypemfile: /config/env/xyz.pem
keystorefile: /secret/pqr.jks
testmode: true
xyz.pem: |-
-----BEGIN PUBLIC KEY——
Line 1
Line 2
Line 3
……………………………………….
-----END PUBLIC KEY-----