Categories
Technology

AES 256 encryption between .NET and PHP

I finally got around to creating some sample code to demonstrate how to do Rijndael (AES-256) encryption between PHP and .NET servers.

They key probelm I found was that mcrypt pads the key with zeroes, where the default behaviour in .NET is PKCS7 padding. Use this line in your/net project to mimic the PHP behaviour.

symmetricKey.Padding = PaddingMode.Zeros;

You also have to remove the padded nulls from the end of string after you do the decryption:

result= result.TrimEnd('\0');

The complete working C# and PHP projects are here:
https://github.com/dchymko/.NET–PHP-encryption

 

 

By darylchymko

Code Wrangler and ultrarunner

One reply on “AES 256 encryption between .NET and PHP”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s