donglu6303 2016-01-09 12:31
浏览 503

在golang中将RSA PrivateKey PEM写入文件

I'm using spacemonkeygo's openssl library to generate an RSA PrivateKey - the library also offers ways to load a private key from a PEM, but I can't figure out how to turn the private key into an encrypted PEM block - anyone got any ideas?

import "github.com/spacemonkeygo/openssl"

// Generate a private key
privateKey, _ := openssl.GenerateRSAKey(2048)

password := "an encryption password"
// Create an encrypted PEM block from the private key?
pem := ???

// Load the PEM file
loadedPrivateKey, _ := openssl.LoadPrivateKeyFromPEMWidthPassword(pem, password)

privateKey == loadedPrivateKey
  • 写回答

1条回答 默认 最新

  • doujingao6210 2016-01-10 13:33
    关注

    Basically you can achieve this with x509.EncryptPEMBlock.

    If your key is surrounded by -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- post- and prefixes you might have to remove them before encryption.

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记