C# Code looks like that (can't change it as it's in a client's system).
namespace Common {
public static class EncryptionHelper
{
private const string cryptoKey = "password";
// The Initialization Vector for the DES encryption routine
private static readonly byte[] IV = new byte[8] { 240, 3, 45, 29, 0, 76, 173, 59 };
/// <summary>
/// Encrypts provided string parameter
/// </summary>
public static string Encrypt(string s)
{
string result = string.Empty;
byte[] buffer = Encoding.ASCII.GetBytes(s);
byte[] k = Encoding.ASCII.GetBytes(cryptoKey);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));
des.IV = IV;
result = Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(buffer, 0, buffer.Length));
return result;
}
}
}
I found client took this class from here: http://johnnycoder.com/blog/2008/07/03/c-encryption-decryption-helper-class/
I'm not very familiar with C# and I need to Decrypt string in PHP encrypted with this code.
When I do "md5($key, true)" I don't get the same result as "MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));", not sure why.
How to convert "byte[] IV" to PHP string ?
Any help would be appreciated. Thank you.