Java / JCE:解密“长”消息使用RSA加密 [英] Java/JCE: Decrypting "long" message encrypted with RSA

查看:117
本文介绍了Java / JCE:解密“长”消息使用RSA加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节[]中包含的消息,用RSA / ECB / PKCS1Padding加密。要解密,我创建一个密码c并启动它与

I've got a message contained in an byte[], encrypted with "RSA/ECB/PKCS1Padding". To decrypt it I create a Cipher c and initiate it with

c = Cipher.getInstance("RSA/ECB/PKCS1Padding");

直到现在,我只解密了小邮件,使用 doFinal()方法,用解密的字节返回一个byte []。

Untill now I have only decrypted small messages, using the doFinal() method, returning an byte[] with the decrypted bytes.

c.init(Cipher.DECRYPT_MODE, privateKey);
byte[] decryptetBytes = c.doFinal(encryptedBytes);

但是在这种情况下,数据较大(约500字节),而 doFinal ) -method抛出异常(javax.crypto.IllegalBlockSizeException:数据不能超过128个字节)。我想我需要使用 update() - 方法,但是我不知道如何使它正常工作。如何做到这一点?

But in this case the data is bigger (approx 500 Bytes), and the doFinal()-method throws an exception (javax.crypto.IllegalBlockSizeException: Data must not be longer than 128 bytes). I guess I need to use the update()- method, but I can't figure out how to get it to work properly. How is this done?

推荐答案

我认为使用RSA加密,除了关键的传输是滥用。

I think using RSA encryption for anything but key transport is abuse.

生成一个对称密码的新密钥,并加密您的批量数据。然后用RSA加密密钥。发送对称加密的密文以及不对称加密的内容加密密钥给您的收件人。

Generate a new key for a symmetric cipher and encrypt your bulk data with that. Then encrypt the key with RSA. Send the symmetrically-encrypted cipher-text along with the asymmetrically-encrypted content encryption key to your recipient.

这篇关于Java / JCE:解密“长”消息使用RSA加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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