2013-01-16 55 views
-2

在Visual Studio 2010 proffessional的C++項目中插入密鑰時,我遇到了一個小問題。爲什麼只是接受我鑰匙中的前2個字符? 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個

任何建議或想法,感謝

+1

爲什麼'我 Angew

+0

我不知道它幫助我,其中的argv [2]有過的argv [I],但我改變了,因爲我被凍得 –

+2

你的代碼看起來像C.一個用C原因++是沒有別想這問題類型。 – juanchopanza

回答

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); 
//****************************************************** 
+0

我使用的類literatecode AES256的,被解密用十六進制文件密鑰 –

+0

適合你(: –

+1

我有同樣的感覺,不知道可能發生了什麼 –

相關問題