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

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

问题描述

我收到了一个包含在 byte[] 中的消息,用RSA/ECB/PKCS1Padding"加密.为了解密它,我创建了一个 Cipher 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() 方法,返回带有解密字节的字节 [].

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() 方法抛出异常(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天全站免登陆