Encrypted in C# and decrypted in PHP - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Encrypted in C# and decrypted in PHP

arikiariki Posts: 1Member
Hi all,

I am working on the php program to decrypted the password which is encrypted by C#. However, the codes show below could not work. Any ideas?

C# coding:
private static String password = @"abc";
private static String saltV = @"123";
private static String hashAlgorithm = "SHA1";
private static int passwordIterations = 2;
private static String iv = @"123456789123456";
private static int keySize = 256;

public static string Encrypt(string text)
byte[] ivBytes = Encoding.ASCII.GetBytes(iv);
byte[] saltBytes = Encoding.ASCII.GetBytes(saltV);
byte[] textBytes = Encoding.UTF8.GetBytes(text);

PasswordDeriveBytes key = new PasswordDeriveBytes(
password, saltBytes, hashAlgorithm, passwordIterations);

byte[] keyBytes = key.GetBytes(keySize / 8);

RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;

ICryptoTransform encryptor =symmetricKey.CreateEncryptorkeyBytes, ivBytes);

MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptor, CryptoStreamMode.Write);
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);

byte[] cipherTextBytes = memoryStream.ToArray();
return Convert.ToBase64String(cipherTextBytes);

************************************************** **********************************
PHP coding:
function decrypt($crytedText) {
$key = "abc";
$iv = "123456789123456";
$text = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$key,$cryptedTe xt, MCRYPT_MODE_CBC, $iv);


Sign In or Register to comment.