Can anyone point me in the right direction.
I am trying to encrypt a string server side (PHP) with a private key and then decrypt it client side (c#) with a public key to verify authenticity of the message sent.
Thanks
Can anyone point me in the right direction.
I am trying to encrypt a string server side (PHP) with a private key and then decrypt it client side (c#) with a public key to verify authenticity of the message sent.
Thanks
Don't try to come up with a custom encryption scheme based on basic crypto algorithms like RSA. Security protocols are very hard to get right; you don't only have to think about encrypting or signing the data, but also man in the middle attacks, replay attacks, padding oracle attacks and whatnot.
I suggest you use a standardised, well-tested security protocol that is easy to use and understand: Use HTTPS.
.NET contains standard functions for RSA encryption/decryption.
To use RSA in PHP, you can find a lot of implementations by Google.
Only problem that you will stumble in future is in transferring data between PHP and .NET programm:
ADDED
RSA is a simple algorithm that isn't hard to implementation by hand.
What about this solution?
What you want to do is usually called signature, not encryption.
Even if in textbooks RSA signature is explained as "encryption with private key, decryption with public one", in reality it uses a slightly different procedure (in the part before the actual "encryption"), and thus you have different functions for signature than for encryption.
For signature in PHP, it looks like you can use the openssl_sign function.
To check the signature in C#, you can use .NET's RSACryptoServiceProvider class, with it's VerifyData method.
Of course, if your goal is simply an authenticated transfer between two entities in the internet (i.e. from server to client), use SSL/TLS, it is the standard solution. You can use your own certificate (or one from your own CA) instead of an costly one from a commercial CA, if you distribute the root certificate with your application.