这是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++代码中的无盐
,我甚至想不出是否值得一试。但所有简单的都不起作用。
有人能帮忙吗?