views:

661

answers:

5

I kown RSACryptoServiceProvider can encrypted with the public key,then it can be decrypted with the private key.

Is possible to encrypt with private key and decrypted with the public key using RSACryptoServiceProvider ?

+1  A: 

No. That's not how any public/private key encryption works. You can only encrypt with the public key, and only decrypt with the private key.

blowdart
Thanks!I want to do Serial Number for protect my software,if RSA can't encrypt with private key,How to do by other way?
guaike
Actually, encrypting with a private key can have it's uses. You can encrypt and release something, and the "public" can decrypt the message with your *public* key, therefore knowing that the encrypted file came from you. It works as a rudimentary form of a signature/authentication. The old dos-based PGP allowed this.
CraigTP
Craig you're talking about signing, which is an entirely different thing. Signing isn't encryption (although it is cryptography). Even then the signature can only be generated with the private key, but checked with the public one.
blowdart
Guakie if you want to do it with encryption then have the client software generate it's own RSA keypair. Then as part of the registration it sends you the public key and you encrypt the serial number for that client against it. That way only that client can decrypt it.
blowdart
Hi,blowdart,thank you for your reply.This is very helpful to me. By the way,If I use the privatekey in the server-side signature generation licence,and client use publicKey validate it,Is this way secure?
guaike
It really depends what you want to do. If all you want is signed issuance of license keys that's fine. If you want to encrypt the license key against a specific client then you should sign it with a private key on the server, and expose the public key so the signature can be checked.
blowdart
A: 

Fortunately no. You can however sign with the private key and verify the signature with the public key.

While the math involve makes sense when the key roles are reversed (and this is how signatures work), encrypting for privacy doesn't make much sense when the decryption key is well know and public.

Remus Rusanu
Well when the math is reversed the inverse function would take a much longer time to finish, an unfeasibly long time.
Sean A.O. Harney
by 'reverse the math' I mean the math doesn't care if e and d in the algorithm are swapped. This is what signing does: encrypt the message hash digest with the private key (the private exponent 'd'). Obviously I did not mean the computation direction can be reversed.
Remus Rusanu
A: 

The security of public key cryptosystems rests on the fact that the sign()/encrypt() function is a one-way function in that it would take an infeasible amount of time to decrypt it without the public key "trap-door".

Also, usually the generated keys are not the same length, although they could be. There is a lot of papers about asymmetric key length with RSA.

Sean A.O. Harney
+1  A: 

Performing the raw RSA operation with the private key is usually called the decryption operation (just as performing it with the public key is called the encryption operation).

It is useful to have access to this operation - for example to implement an operation that is not supported by the framework.

The operation exists: it is the DecryptValue-method, which is defined by RSACryptoServiceProvider's base-class: System.Security.Cryptography.RSA. Unfortunately, it is not supported by RSACryptoServiceProvider (since the underlying win32-api, CryptoAPI, does not support it). If you could get hold of another .NET-implementation of the RSA-class, you would be able to do it, however.

Rasmus Faber
+1  A: 

Just to clear things up a bit:

RSA can be used either for encryption (ensuring that Eve cannot read messages that Alice sends to Bob) or for signing (ensuring that if Alice sends a message to Bob, Bob knows that it was actually Alice that sent the message, and not Eve pretending to be Alice)

RSA generates a pair of keys - a public key and a private key. RSA is designed so that if you apply the public key and then apply the private key, or vice versa, you will get the same message back. And the public key cannot be derived from the private key (or vice versa).

To use RSA for encryption, Alice encrypts the message using Bob's public key. The only way to read this message is with Bob's private key, which only he has. Thus Eve can't read the message because he does not have this key. On the other hand, this provides no authentication of the source of the message. Eve can also get Bob's public key (since it's public) and send messages to Bob, pretending to be Alice.

To use RSA for signing, Alice takes a hash of the message, encrypts the hash using her own private key, and appends the result (this is the signature) to the message. Eve can of course still decrypt this using Alice's public key. However, Bob can decrypt the signature using Alice's public key and see if it matches. If it does, it must have been encrypted using Alice's private key, which only she has, so it must have come from Alice.


Now, I'm not familiar with the .NET cryptography API, so I'm not sure if it works exactly as described here. But this explanation might help you understand some of the answers you are getting.

Alex319