rsa加密密文修改

Modification of rsa encrypted cipher text

我遇到了以下问题:

我使用 RSA 私钥加密给定的纯文本。我想通过不安全的通道将它发送到另一个应用程序。另一个应用程序只知道 public 键。

中间人是否可以更改部分密文,以便解密得到修改后的文本?

我在我的 Java 应用程序中自己尝试了这个,但如果我这样做,我总是得到


<code>javax.crypto.BadPaddingException: Decryption error
    at sun.security.rsa.RSAPadding.unpadV15(RSAPadding.java:380) ~[na:1.8.0_131]
    at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:291) ~[na:1.8.0_131]
    at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:356) ~[sunjce_provider.jar:1.8.0_112]
    at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:389) ~[sunjce_provider.jar:1.8.0_112]
    at javax.crypto.Cipher.doFinal(Cipher.java:2048) ~[na:1.8.0_121]

我在我的 Java 应用程序中使用算法 "RSA/ECB/PKCS1Padding" 进行加密和解密。

此致

问题的正确答案由 Maarten Bodewes 给出:

"I use a RSA private key to encrypt a given plain text.". You should stop right there. Encryption with an RSA private key is not signature generation and it does not provide confidentiality of the message either; it is not a secure cipher. You encrypt with the public key and decrypt with the private key, period. –