Re: Encrypting using RSA private Key

No, that is a violation of how RSA is intended to be used, so Windows
prevents you doing that. You sign and decrypt with the private key, not

Joe K.
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
"Jeronimo Bertran" <jeronimo.bertran@xxxxxxxxxxxxxxxx> wrote in message

Is it possible to encrypt using the RSA private key and decrypt using the
public key? I am able to do the opposite but when I try to decrypt using
the private key I get a "Bad Key" Exception. Here is an example:

rsa = new RSACryptoServiceProvider();
RSAParameters publicKey = rsa.ExportParameters(false);
RSAParameters privateKey = rsa.ExportParameters(true);
byte[] testPlainData = new byte[] { 0x01, 0x02, 0x03 };
byte[] enc = rsa.Encrypt(testPlainData, false);
byte[] plain = rsa.Decrypt(enc, false);

enc = rsa.Encrypt(testPlainData, false);
rsa.Decrypt(enc, false);

The first encryption and decryption work fine. The second encryption
(using the private key) seems to work but the decryption using the public
key throws the exception.




Relevant Pages

  • [OT] Re: Basic question about Public Private Key Pairs
    ... > and private keys allow me to decrypt, but vice versa is not possible (or ... a public key and a corresponding private key. ... You can encrypt something with each key; ...
  • Re: Back Doors
    ... >> Design into the system a master key. ... Encrypt that with public key. ... Decrypt random symmetric key with private key. ...
  • Re: More on learning "Public Key Authentication"
    ... let me say that in public key ... >> encrypt the result with Alice's public key. ... >> is sent to Alice who decrypts the message with her private key (which ... > encrypted with my private key and they can then decrypt it with the ...
  • Re: RSACryptoServiceProvider decrypt with public key
    ... key/decrypt with the private key and encrypt with the private key/decrypt ... encrypt data and send it back to Alice. ... only she can decrypt Bob's data. ... see the public key and the encrypted data, but she could not decrypt Bob's ...
  • Re: RSA .crt and .key file formats?
    ... > and private key file (actually, the private key file, from what I can ... Basically, for RSA signatures, and for RSA decryption, you need to ... needs only the modulus n and the private exponent d. ... setting is to choose a random binary value K, encrypt it ...