Click to See Complete Forum and Search --> : Need help with decryption


mparfrey
05-25-2006, 03:45 PM
Hello all I am trying to grab data and decrypt it from a .NET site. I have been provided the .NET code to decrypt, but need to convert it to php. I do not know how to convert this code. Please see below for decryption. Anyone know how to convert this?



public string DecryptData(string Password, string encryptedBase64Value)
{


string __Data;
byte[] __EncryptedBytes;
byte[] __TextBytes;
System.Security.Cryptography.TripleDES __CryptoProvider;
System.Security.Cryptography.PasswordDeriveBytes __PasswordDeriveBytes;
System.Security.Cryptography.CryptoStream __CryptoStream;
System.IO.MemoryStream __MemoryStream;


__CryptoProvider = System.Security.Cryptography.TripleDES.Create();
__CryptoProvider.IV = new byte[8];
__PasswordDeriveBytes = new System.Security.Cryptography.PasswordDeriveBytes(Password, new byte[0]);
__CryptoProvider.Key = __PasswordDeriveBytes.CryptDeriveKey("RC2", "MD5", 128, new byte[8]);


__EncryptedBytes = System.Convert.FromBase64String(encryptedBase64Value);


__MemoryStream = new System.IO.MemoryStream(encryptedBase64Value.Length);


__CryptoStream = new System.Security.Cryptography.CryptoStream(__MemoryStream, __CryptoProvider.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
__CryptoStream.Write(__EncryptedBytes, 0, __EncryptedBytes.Length);
__CryptoStream.FlushFinalBlock();


__TextBytes = new byte[__MemoryStream.Length];


__MemoryStream.Position = 0;
__MemoryStream.Read(__TextBytes, 0, (int)__MemoryStream.Length);


__CryptoStream.Close();


__Data = System.Text.Encoding.UTF8.GetString(__TextBytes);


return __Data;


}