PhonicUK
PhonicUK

Reputation: 13844

'Backwards' public/private key encryption in C#, how would I go about this?

I want my client side application to be able to decrypt some data generated server side, but not be able to encrypt data such that it can decrypt it again.

So the server can encrypt and decrypt, client can only decrypt.

RSA can't be used for this obviously, as having the private key (to decrypt) means you have to also have the public key.

I need to be able to ensure that the data I'm receiving from the server really did come from the server and wasn't generated by a third party. Giving the client application the public key would mean you couldn't do this.

Any advise on the best way to approach this would be most welcome.

Upvotes: 4

Views: 712

Answers (2)

Create two RSA keypairs - one (A) for encryption (and put the private key to the client-side application) and another (B) for signing (private key is kept on the server). Now when you send the data to the client, encrypt it using the public key from keypair A and sign it using the private key from keypair B. Signing is done by calculating a cryptographic signature over the hash of the data (to make processing easier and increase it's speed). Signing is normally not done over the data itself due to very low speed of asymmetric cryptography.

This procedure is standard and is supported by all RSA implementations (if the are worth at least a penny). If you plan to use X.509 certificates, then PKCS#7 (later evolved to CMS and to CAdES) standard is your friend. If you go with plain RSA keys, then you will need to invent your own format (but that's not a big hassle).

There's one thing to consider though: you are passing the private key to the application, which means that it becomes available to the user as well and leakage of data is possible that way. Did you consider this side effect?

Upvotes: 0

Ben Voigt
Ben Voigt

Reputation: 283614

Simple: You encrypt with the private key, then anyone can decrypt with the public key. This is the basis of certificate signing.

Normally you would encrypt only a hash, and not the entire data block, since this is faster.

Upvotes: 4

Related Questions