jrahma;11044841 wrote:I have .NET WinForm application in C# and I will make Web application for it using PHP.
This sounds like you are writing some kind of desktop application for windows machines as a client for a PHP server. Is
jrahma;11044841 wrote:I would like to ask what's the best way to encrypt / decrypt user authentication so it wll work on both WinForm and PHP portal?
Not sure what you mean by 'encrypt/decrypt user authentication.' Authentication refers to the process by which you verify that a user is in fact who they say they are. Do you mean to say that you want to encrypt the communications that establish authentication between client and server? If so, what's wrong with using HTTPS?
Note that your .NET code refers to RFC 2898 which is a document from RSA labs describing PKCS #5: Password-Based Cryptography Specification Version 2.0.
user_password = cipher_utility.Encrypt<RijndaelManaged>(result, "xxxx", "xxxx");
Looks like you are encrypting passwords. Is this simply because you want to encrypt a password just so you can send it to the server? I expect HTTPS would be a much more convenient and effective way to do this because the HTTPS protocol will automatically negotiate an encryption scheme and you won't have to store encryption keys/passwords on both client and server.
If you absolutely must be able to encrypt/decrypt messages to share with that .NET class, the key of course will be to make PHP functions that mirror your .NET encrypt/decrypt functions. It lookes to me like the code is using the salt and password to get rgb which is an object of type DeriveBytes (?) and then extracting a key and initialization vector from that object. Note also that the encryption and decryption steps involve base64 encoding.
It's been my experience that getting messages to decrypt is pretty hard. There's pretty much only one way to get something to decrypt. You need not just the right credentials but also the right process exactly. And because encrypted text is intentionally gibberish, you never really know if you are headed the right direction until the message is completely decrypted. You can't look at intermediate steps (e.g., the base64 decoded cipher text) and know if you are headed the right direction or not.