-2

在Visual Studio 2010专业版的ac ++项目中插入密钥时遇到一个小问题。

当我放键时,只接受前两个键,当你放一个以前两个字符开头的类似键时,这可能是个问题。

但是,当我将密钥直接放入十六进制字符时,会验证所有内容。

我提前说清楚了,我学c++知道的很少,这就是我目前所做的。

    //****************** AES decryption ********************
const int size = 32;
unsigned char aesKey[size];
char* p;

for (int i = 1; i < argc || i < size; ++i)
{
    aesKey[i] = (unsigned char)strtol(argv[2], &p, 16);
} 

unsigned char *buf;

aes256_context ctx;
aes256_init(&ctx, aesKey);

for (unsigned long i = 0; i < lSize/16; i++) {
    buf = text + (i * 16);
    aes256_decrypt_ecb(&ctx, buf);
}

aes256_done(&ctx);
//******************************************************

我有参数 argv[2] 的地方是因为我必须使用参数 2

任何建议或想法,谢谢

4

1 回答 1

1

这段代码可以有很多修复,但这是我能看到的基本

//****************** AES decryption ********************
const int size = 32;
unsigned char aesKey[size];
char* p;

//check you have argv[2]
if (argc < 3)
{
    //TODO: return or handle the error as you wish...
}

//i need to start from 0 (it's a zero base index)
//argc = argument count. and this should not be here
//you have 3 arguments and this is why it read 2 chars...
for (int i = 0;i < size; ++i)
{
    aesKey[i] = (unsigned char)strtol(argv[2], &p, 16);
} 

unsigned char *buf;

aes256_context ctx;
aes256_init(&ctx, aesKey);

//I don't know where lsize is coming from but I would calculate the division out side:
unsigned long myMax = lSize/16;
for (unsigned long i = 0; i < myMax; i++) {
    buf = text + (i * 16);
    aes256_decrypt_ecb(&ctx, buf);
}

aes256_done(&ctx);
//******************************************************
于 2013-01-16T12:33:58.333 回答