为什么只接受我密钥的前两个字符?c++
Why just accept me the first 2 characters in the key? C ++
我在visual studio 2010 professional的c++项目中插入密钥时遇到了一个小问题。
当我放入密钥时,只接受前两个密钥,当您放入以前两个字符开头的类似密钥时,这可能会出现问题。
但是,当我直接将密钥放入十六进制字符中时,将验证所有。
我事先明确我所知甚少,我正在学习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
有任何建议或想法,谢谢
这段代码可以有很多修复,但这是基本的我可以看到
//****************** 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);
//******************************************************
相关文章:
- 如何读取单个字符并在输入两个字符序列时输出? 使用 while 循环和C++
- 在函数中连接两个字符,并在 C++ 中返回输出
- 舍入 QDecDouble 值,精度最多为两个字符
- 计算两个字符序列
- 在c++中连接两个字符
- 有没有办法我可以从 istringstream 中读取两个字符
- 如何查看两个字符变量是否相等
- 使用位于 C 字符串中的两个字符*获取子字符串
- 比较两个字符的问题
- 如何修复密码条目,它一次输入两个字符
- 字符串构造函数将两个字符* 放入另一个 std::string 在 C++14 中有效,但不适用于 C++17
- 将两个字符数组相互添加
- 在 c++ 中添加两个字符
- 如何删除QString的前两个字符
- 如何使用两个字符来控制 C++ 程序的流程
- 如何将两个字符或字符串数组附加到一个数组中
- 如何从两个字符之间的文件中提取整数
- 删除两个字符之间的文本
- std::setw() 将特殊字符视为两个字符
- 比较两个字符*是否相等