4
C#代碼看起來像這樣(無法將其更改爲客戶端系統中的代碼)。在C#中使用TripleDES加密的字符串需要使用PHP解密
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;
}
}
}
我發現客戶端把這個班從這裏:http://johnnycoder.com/blog/2008/07/03/c-encryption-decryption-helper-class/
我不是很熟悉C#,我需要在PHP解密字符串 此代碼加密。
當我做「md5($ key,true)」我得不到與「MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));」相同的結果,不知道爲什麼。
如何將「byte [] IV」轉換爲PHP字符串?
任何幫助,將不勝感激。 謝謝。
你肯定'MD5.ComputeHash()',甚至是你的C#類,返回原始二進制散列? 'md5($ key,true)'_will_輸出原始二進制散列,所以這可能是你的不一致的根源。 – Fuselight
我已經設法得到相同的MD5字符串,但仍然無法解密它。 – staskus