且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么RSA加密可以返回用C#和Java不同的结果?

更新时间:2022-12-20 08:29:12

RSA加密是随机的。对于给定的公开密钥和给定的消息,每次尝试在加密产生字节的独特序列。这是正常的预期;随机字节被注入作为填充阶段的一部分,而不是注入随机字节将导致弱的加密系统。解密时,填充字节的位置和删除,原始邮件恢复毫发无损。

RSA encryption is randomized. For a given public key and a given message, each attempt at encryption yields a distinct sequence of bytes. This is normal and expected; random bytes are injected as part of the padding phase, and not injecting random bytes would result in a weak encryption system. During decryption, the padding bytes are located and removed, and the original message is recovered unscathed.

因此​​,预计您将获得与Java和C#不同的加密邮件,而且,如果你运行Java或C#代码的两倍。

Hence it is expected that you will get distinct encrypted messages with Java and C#, but also if you run your Java or C# code twice.