如何使用RSA加密大文件? [英] How to encrypt large file with RSA?

查看:373
本文介绍了如何使用RSA加密大文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码 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
main.main()
    /tmp/sample.go:28 +0xfa

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

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?

推荐答案

RSA只能加密小于(或等于)密钥长度的数据.

RSA can only encrypt data smaller than (or equal to) the key length.

答案是使用对称算法(例如AES)加密数据,该算法旨在加密大小数据.

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

如果需要RSA公钥/私钥对,请使用RSA加密对称(AES)密钥.这就是所谓的混合加密,实质上就是HTTPS加密数据的方式.

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 how HTTPS encrypts data.

但是,除非需要公用/专用密钥对,否则可能不需要RSA加密对称密钥.在一般情况下,仅使用对称(AES)和该密钥.公钥/私钥对的用例是什么?

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?

这篇关于如何使用RSA加密大文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆