C # code looks like this (cannot change it, as in the client system).
namespace Common {
public static class EncryptionHelper
{
private const string cryptoKey = "password";
private static readonly byte[] IV = new byte[8] { 240, 3, 45, 29, 0, 76, 173, 59 };
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 the client took this class from here: http://johnnycoder.com/blog/2008/07/03/c-encryption-decryption-helper-class/
I am not very familiar with C #, and I need to decrypt a string in PHP, encrypted using this code.
When I do "md5 ($ key, true)", I do not get the same result as "MD5.ComputeHash (ASCIIEncoding.ASCII.GetBytes (cryptoKey))", I don’t know why.
How to convert "byte [] IV" to a PHP string?
Any help would be greatly appreciated. Thanks.
source
share