英文:
Store and read a private key in appsettings.json
问题
我们不允许在我们的存储库中存储私钥,所以我们将其放在章鱼中,并替换其中的私钥。
我们使用该密钥连接到外部SFTP服务器。
将该值复制到章鱼时,我丢失了换行符LF。当我稍后读取并使用它时,出现了一个错误,说密钥无效。
最佳的读取或存储密钥的方法是什么?
英文:
We are not allowed to store private keys in our repository so we place it in octopus and replace it in it.
We use the key to connect with an external sftp server
Copying the value to octopus I loose the line feed character LF. When I read and use it later I get an error, that the key is invalid.
What would be the best way to read or store the key?
答案1
得分: 4
将私钥转换为Base64格式后再存储到Octopus中。这种编码方式会保留所有字符,包括LF(换行符)。当您从Octopus检索密钥时,将其从Base64解码回其原始格式,您应该可以保留LF。
在从Octopus读取私钥时,仔细检查其格式。确保它与SFTP连接的预期格式匹配。例如,SSH密钥通常具有特定的头部和尾部行,如 -----BEGIN RSA PRIVATE KEY-----
和 -----END RSA PRIVATE KEY-----
。
英文:
Convert the private key to Base64 before storing it in Octopus. This encoding will preserve all characters, including LF. When you retrieve the key from Octopus, decode it from Base64 back to its original format, and you should have the LF preserved.
Double-check the format of the private key when you read it from Octopus. Make sure it matches the expected format for SFTP connections. For example, SSH keys typically have specific header and footer lines like -----BEGIN RSA PRIVATE KEY-----
and -----END RSA PRIVATE KEY-----
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论