2016-10-25 15:24
浏览 1.0k


Code https://play.golang.org/p/CUEqjsJq5c


panic: crypto/rsa: message too long for RSA public key size

goroutine 1 [running]:
panic(0x4a6d80, 0xc420010420)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1
    /tmp/sample.go:28 +0xfa

File size 811 byte (for test encrypt self source file). I want encrypt some bigger files, 1..500 mb. Can I do it with RSA or need use some other methods?

图片转代码服务由CSDN问答提供 功能建议

代码 https://play.golang.org/p/CUEqjsJq5c


 恐慌:crypto /  rsa:消息太长,无法获得RSA公钥大小
goroutine 1 [正在运行]:
 /usr/local/go/src/runtime/panic.go:500 + 0x1a1 
main.main  ()
 /tmp/sample.go:28 + 0xfa 

文件大小811字节(用于测试加密自身源文件)。 我想加密一些更大的文件1.500 mb。 我可以使用RSA还是需要使用其他方法?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongqian8265 2016-10-25 15:51

    RSA can only encrypt data smaller than the key length.

    The answer is to encrypt the data with a symmetric algorithm such as AES which is designed to encrypt small and large data.

    If an RSA public/private key pair are required encrypt the symmetric (AES) key with RSA. This is referred to as hybrid encryption and in essence is hoe HTTPS encrypts data.

    But it is may not necessary to RSA encrypt the symmetric key unless a public/private key pair are required. In the general case one just uses symmetric (AES) and that key. What is the use case for a public/private key pair?

    解决 无用
    打赏 举报

相关推荐 更多相似问题