dongre9937 2010-06-24 03:55
浏览 313
已采纳

如何使用Go编程语言使用从PEM文件读取的RSA私钥进行加密?

How do I do the equivalent of the following C++ code in go?

RSA *key = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL);
std::vector<CK_BYTE> out(128);
RSA_private_encrypt(in.size(), &in[0], &out[0], key, RSA_PKCS1_PADDING)

I've looked at the Go rsa package. It looks like EncryptPKCS1v15() may be the equivalent of RSA_private_encrypt(). But I don't see how to create a PrivateKey object other than with GenerateKey(), which (one can confirm by looking at the source) generates one using random prime numbers.

Do I need to figure out how to decode a PEM file so pull out the PrivateKey fields' values?

Update: The equivalent to the above C++ code in Python is:

from M2Crypto import RSA
rsa_private_key = RSA.load_key('privkey.pem')
encrypted = rsa_private_key.private_encrypt(digest, RSA.pkcs1_padding)

Is there an existing equivalent in Go?

  • 写回答

2条回答 默认 最新

  • dongmu6578 2010-06-24 23:36
    关注

    The equivalent function appears to be SignPKCS1v15. The function ParsePKCS1PrivateKey in the crypto/x509 package appears to be the closest to what you need to read in your existing private key, but I'm not sure the PEM format is exactly compatible, which it must be for this to work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料