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

后端 未结 3 1482
借酒劲吻你
借酒劲吻你 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 17:00

    RSA is built into .NET: System.Security.Cryptography.RSA.

    Encrypting using the public key and decrypting with the private key is one of the most common things people do with asymmetric algorithms, it allows anybody to send you something securely.

    If you do it the other way: encrypt using the private key, and decrypt with the public key then it proves the message was sent by the holder of the private key. But because anyone presumably can get hold of the public key, people don't tend to encrypt the whole message, they instead just sign a hash of the data using the private key. Hence RSACryptoServiceProvider has Sign__ and Verify__ methods to do just that.

    Still, there are Encrypt/Decrypt methods if your partner insists.

    Saying that, I've found the Microsoft crypto classes a bit tricky to deal with and lacking in certain areas and much prefer the Bouncy Castle libraries.

提交回复
热议问题