0

I'm trying to find an AES encryption method that will allow me to encrypt a string in PHP and use the encrypted string to be decrypted in C#

Can anyone help me out here. I've looked at nearly all the examples on the net and can't find a matching one that will let me do what I want.

Thanks

Sandeep Bansal
  • 6,280
  • 17
  • 84
  • 126

2 Answers2

6

The problem with PHP is that mcrypt only supports null padding. C# does not support null padding for good reason, it goes haywire if you're encrypting binary information. If you switch to OpenSSL for your encryption on PHP you will get better padding options. Once you have switched you simply need to ensure the block size, mode and padding options are the same on both sides.

blowdart
  • 55,577
  • 12
  • 114
  • 149
  • The thing is I want to attempt this without the use for a separate DLL for openssl, my preference would be AES. If there's something like AES that will do the job then please let me know, thanks. – Sandeep Bansal Jun 23 '11 at 15:59
  • @Sandeep Blowdart's answer still applies. You won't be able to use mcrypt which means you have to implement say OpenSSL instead. – Security Hound Jun 23 '11 at 16:07
  • You don't need a DLL for OpenSSL, you need to use OpenSSL on the PHP side. OpenSSL providers better AES support in PHP than mcrypt, and you will be able to use the standard .NET AES classes to decrypt. – blowdart Jun 23 '11 at 16:10
2

I would recommend phpseclib, a pure PHP AES implementation. It's interoperable with OpenSSL as demonstrated thusly:

AES Encrypt in PHP to decrypt in openssl

Community
  • 1
  • 1