在Go语言中进行适当的非对称文件加密。

huangapple go评论81阅读模式
英文:

Proper asymmetric file encryption in Go

问题

我需要一种方法,允许多个人加密各种文件,但只有一方能够读取所有文件。我按照网上的各种示例,用Go语言编写了一个程序,但在某个时候出现了以下错误:

加密错误:crypto/rsa: RSA公钥大小不适用于消息长度

RSA是否是错误的选择?如果我将文件分成多个块并对它们进行加密,是否可以?是否有一种可以轻松使用的非对称分块密码?

我阅读了这里的讨论,其中提到RSA不是正确的选择。

你还能提供一个示例吗?

英文:

I need a way to allow multiple people encrypting various files but only one party been able to read them all. I wrote a program in Go by following various online examples but at some point I got the following error:

Error from encryption: crypto/rsa: message too long for RSA public key size

Is RSA the wrong way to go? Is it ok if I break the file into multiple chunks and encrypt them? Is there an asymmetric block cipher that I can easily use?

I read the discussion here and it is said that RSA is not the proper way to go.

Can you also provide with an example?

答案1

得分: 0

如果您需要对大于密钥大小的数据进行公钥非对称加密,您需要使用混合加密。基本上,这就是HTTPS的工作原理。

混合加密是指使用对称密钥加密(如AES)对数据进行加密,然后使用非对称密钥加密(如RSA或EC(椭圆曲线)密码学)对该密钥进行加密。

不要将文件分成多个块并对其进行加密。

英文:

If you need public key asymmetric encryption for data larger than the key size you need to use hybrid encryption. Essentially this is how HTTPS works.

Hybrid encryption is where the data is encrypted with symmetric key encryption such as AES and that key is encrypted with asymmetric key encryption such as RSA or EC (Elliptic Curve) Cryptography.

Do not break the file into multiple chunks and encrypt them.

答案2

得分: 0

所以我最终使用了GPG,我的服务有一个独特的私钥,我与用户分享公钥。

英文:

So I ended up using GPG and my service has one unique private key and I share the public one with my users.

huangapple
  • 本文由 发表于 2016年11月1日 09:49:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/40353070.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定