Port RSA encryption Java code to C#

后端 未结 1 1848
天命终不由人
天命终不由人 2021-02-03 14:42

I\'m trying to port the following Java code to a C# equivalent:

public static String encrypt(String value, String key) throws InvalidKeySpecException, NoSuchAlgo         


        
1条回答
  •  一个人的身影
    2021-02-03 15:17

    As an educated guess, I would say that Java adds random padding to create a stronger encryption.

    Most practical implementations of RSA do this, and as the wiki puts it...

    Because RSA encryption is a deterministic encryption algorithm – i.e., has no random component – an attacker can successfully launch a chosen plaintext attack against the cryptosystem, by encrypting likely plaintexts under the public key and test if they are equal to the ciphertext. A cryptosystem is called semantically secure if an attacker cannot distinguish two encryptions from each other even if the attacker knows (or has chosen) the corresponding plaintexts. As described above, RSA without padding is not semantically secure.

    This is likely why your two methods don't output the same.

    0 讨论(0)
提交回复
热议问题