当在 CryptoPP 中使用 DefaultEncryptorWithMAC 时,它的核心似乎是使用这个 Mash 函数
// The purpose of this function Mash() is to take an arbitrary length input
// string and *deterministicly* produce an arbitrary length output string such
// that (1) it looks random, (2) no information about the input is
// deducible from it, and (3) it contains as much entropy as it can hold, or
// the amount of entropy in the input string, whichever is smaller.
static void Mash(const byte *in, size_t inLen, byte *out, size_t outLen, int iterations)
{
if (BytePrecision(outLen) > 2)
throw InvalidArgument("Mash: output legnth too large");
size_t bufSize = RoundUpToMultipleOf(outLen, (size_t)DefaultHashModule::DIGESTSIZE);
byte b[2];
SecByteBlock buf(bufSize);
SecByteBlock outBuf(bufSize);
DefaultHashModule hash;
unsigned int i;
for(i=0; i<outLen; i+=DefaultHashModule::DIGESTSIZE)
{
b[0] = (byte) (i >> 8);
b[1] = (byte) i;
hash.Update(b, 2);
hash.Update(in, inLen);
hash.Final(outBuf+i);
}
while (iterations-- > 1)
{
memcpy(buf, outBuf, bufSize);
for (i=0; i<bufSize; i+=DefaultHashModule::DIGESTSIZE)
{
b[0] = (byte) (i >> 8);
b[1] = (byte) i;
hash.Update(b, 2);
hash.Update(buf, bufSize);
hash.Final(outBuf+i);
}
}
memcpy(out, outBuf, outLen);
}
根据此页面http://www.cryptopp.com/wiki/DefaultEncryptorWithMAC
DefaultEncryptorWithMAC 使用 2-key Triple DES 作为默认加密器,并使用 SHA1 作为 MAC 的默认散列。分组密码在 CBC 模式下运行。密码是混搭的,而不是使用基于密码的密钥派生函数派生的。由于使用了基于时间和时钟的盐,每次运行 DefaultEncryptorWithMAC 都会产生不同的结果。
我正在尝试用另一个库读取这个加密字符串,并且真的很挣扎,即执行 DefaultDecryptorWithMAC 的等效操作(http://www.cryptopp.com/wiki/DefaultDecryptorWithMAC)
如果我将我的密钥通过并在线 SHA1 加密,我得到的结果与上面的 Mash 函数不同吗?
根据上面的网页,它似乎表明它正在使用标准加密技术,我无法用其他任何东西来解密结果
希望这里有人有从这个库中解密这些函数结果的经验
提前致谢