Using an RSA Public Key to decrypt a string that was encrypted using RSA Private Key

后端 未结 3 1484
借酒劲吻你
借酒劲吻你 2020-12-13 16:30

I know the main answer I am likely to get is why the hell would you want to do that?!

Unfortunately despite my protests I have to do it, even though I know it makes

3条回答
  •  鱼传尺愫
    2020-12-13 16:55

    RSA is not meant to encrypt arbitrary data, even less arbitrary data length (like @Iridium already told you). The limit depends on the padding used and using the padding is very important (enough that MS won't let you call EncryptValue and DecryptValue directly).

    The right way to do this is to encrypt your string using a symmetric cipher (like AES) then encrypt the secret key using the RSA public key.

    The other party will be able to decrypt the secret (AES) key using the RSA private key. Then using the key decrypt your string.

    I have an old (but still up to date) blog entry on the subject that includes source code (C#).

提交回复
热议问题