1

I have a C# code to decrypt data, now I'm trying to make the same in PHP but I can't get the same result. I know that I missing something but I don't know how to transfer this to PHP. Any ideas? Thanks.

This is the C# code:

public static string Decrypt(string cipherData, string key) { byte[] salt = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; PasswordDeriveBytes cdk = new PasswordDeriveBytes(key, salt); byte[] kex = cdk.CryptDeriveKey("RC2", "SHA1", 128, salt); RijndaelManaged rijKey = new RijndaelManaged(); rijKey.Mode = CipherMode.CBC; byte[] textBytes = Convert.FromBase64String(cipherData); ICryptoTransform decryptor = rijKey.CreateDecryptor(kex, IV); MemoryStream memoryStream = new MemoryStream(textBytes); CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read); byte[] pTextBytes = new byte[(textBytes.Length - 1) + 1]; int decryptedByteCount = cryptoStream.Read(pTextBytes, 0, pTextBytes.Length); memoryStream.Close(); cryptoStream.Close(); return Encoding.UTF8.GetString(pTextBytes, 0, decryptedByteCount); } 

This is the PHP code trying to make the same (I know that it is incomplete):

function Decrypt($data, $key) { $method = 'rc2-cbc'; $iv = '0000000000000000'; return utf8_encode(openssl_decrypt($data, $method, sha1($key), OPENSSL_ZERO_PADDING, $iv)); } 
2
  • 1
    link 1 link 2 link 3 ...plus 3000 more Commented Nov 28, 2014 at 15:57
  • Thanks Plutonix, I will check the links Commented Nov 28, 2014 at 15:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.