0

我有这段代码加密我的文件:

static const char* KEY = "Test";

...

    FILE* pFile = fopen("skills.dat", "wb+");

char* result = new char[ (TOTAL_SKILLS + 1) * sizeof(int)];
memset(result, 0, (TOTAL_SKILLS + 1) * sizeof(int));


int counter = 0;
while(counter != TOTAL_SKILLS + 1)
{
    char szSkillName[40] = "";
    strcpy(szSkillName,(buffer + (counter * 0x12C)));

    int skillDelay = *(int*)(buffer + (counter * 0x12C) + 228);


    *(int*)(result + (counter * 4)) = skillDelay;

    counter++;
    printf("Skill %s saved.\r\n",szSkillName);
}
CRC4 crc;
crc.Encrypt(result,KEY, (TOTAL_SKILLS + 1) * sizeof(int));

fwrite(result,1, (TOTAL_SKILLS + 1) * sizeof(int),pFile);
fclose(pFile);

的内容buffer可能并不重要,问题是我无法解密加密的数据。显然,我使用的是相同的密钥,但解密的结果与原始输入缓冲区不同。可能会发生什么?这听起来很奇怪……

解密代码:

LPCSTR name = "skills.dat";
    int counter = 0;
std::ifstream myFile(name, std::ios::binary | std::ios::out );

if(myFile.fail())
{
    myFile.close();
    return false;
}

int len = (TOTAL_SKILLS + 1) * sizeof(int);
char* buffer = new char[len];

myFile.read(buffer,len);
myFile.close();

CRC4 crc;
crc.Decrypt(buffer,KEY,len);
4

1 回答 1

0

我通过删除 Encrypt 函数和密钥生成哈希中的 SWAP 宏解决了我的问题。

于 2012-07-31T02:13:41.310 回答