这是 C++ 代码:
CCryptMD5Hash md5;
CCryptProv cprov;
PCWSTR pszPassword = <password>;
BYTE* data = <array of bytes>;
ATL::CCryptDerivedKey m_CryptKey;
md5.Initialize( cprov );
md5.AddData(reinterpret_cast<const BYTE*>(pszPassword), wcslen(pszPassword) * sizeof(wchar_t));
m_CryptKey.Initialize( cprov, md5, CALG_DES);
std::vector<BYTE> buff(data, data + size);
DWORD cbBufSize = buff.size();
m_CryptKey.Decrypt(TRUE, &buff.front(), &cbBufSize));
它成功地将字节数组解码为类似“ABC-DEF-2\ZXCVBNMHOHUH,2020100”的字符串。
这是我正在尝试编写的相应 .NET 代码:
byte[] salt = new byte[0];
byte[] input = <array of bytes>;
byte[] pwd = Encoding.Unicode.GetBytes(<password>);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
PasswordDeriveBytes pdb = new PasswordDeriveBytes(pwd, salt);
des.Key = pdb.CryptDeriveKey("DES", "MD5", 0, des.IV);
MemoryStream ms = new MemoryStream(input);
CryptoStream ds = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(ds, Encoding.Unicode);
string s = sr.ReadToEnd();
它的输出字符串是“몶뛛跬DEF-2\ZXCVBNMHOHUH,2020100”。因此,前四个字符被错误解码。更改盐会使这些字符不同。
由于C++ 代码中没有盐,我什至想不出尝试的价值。但所有简单的也不起作用。
有人可以帮忙吗?