RSA的加密数据长度非常大 [英] Encrypted data length is very large with RSA

查看:3787
本文介绍了RSA的加密数据长度非常大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望加密数据与原始文本的长度相同,因为我必须遵守长度约束。我正在使用 BouncyCastle

I want that encrypted data have the same length as my original text, because I must respect the constraint of length. I am using BouncyCastle.

这是我生成密钥对的代码:

Here's my code to generate the keys pair:

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(512);
KeyPair keypair = keyGen.genKeyPair();
PublicKey pub = keypair.getPublic();
byte[] pubs = pub.getEncoded();

这是我的加密代码:

Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
PublicKey pk = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(pubs));
cipher.init(Cipher.ENCRYPT_MODE, pk);
byte[] cipherBytes = cipher.doFinal(plainArray);

编码数据非常大,我可以做些什么来制作原始数据?

The encoded data is very large, what can I do to make as small as original data ?

推荐答案

没什么,至少不是关于RSA。 RSA要求一定量的填充是安全的,并且由于数据将被任何压缩方法视为随机数据,您也无法压缩它。

Nothing, at least not regarding the RSA. RSA requires a certain amount of padding to be secure, and as the data will be seen as random data by any compression method, you cannot compress it either.

当然,您不应该直接使用RSA直接加密数据,而应该加密随机会话/数据密钥。但即使这样,您也会将加密的会话密钥作为开销。

Of course, you should not directly encrypt data directly using RSA, you should encrypt a random session/data key instead. But even then, you will have the encrypted session key as overhead.

您可以使用Elliptic Curve Cryptography(输出为非对称加密数据/密钥)删除一些位这是密钥大小最小的两倍,但密钥大小要小得多,以达到相同的安全级别)。虽然EC密码学不是很温和,但它有很多复杂性。

You can remove some bits for the asymmetric encrypted data/key by using Elliptic Curve Cryptography (the output of which is double the key size minimum, but key sizes are much smaller to achieve the same level of security). EC cryptography is not for the meek though, it has lots of complexity.

512位RSA被认为是不安全的。最少使用1024或保留 http://www.keylength.com/。

512 bit RSA is considered insecure by the way. Use 1024 as minimum or keep to the ECRYPT II or NIST recommendations listed at http://www.keylength.com/ .

这篇关于RSA的加密数据长度非常大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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