Click here to Skip to main content
15,916,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i need to read last 32 byte of a binari file and use them as array of hex (it's a key for decryption).
if i use an hardcoded key like


C#
unsigned char aesKey[32] = {
    0x53, 0x28, 0x40, 0x6e, 0x2f, 0x64, 0x63, 0x5d, 0x2d, 0x61, 0x77, 0x40, 0x76, 0x71, 0x77, 0x28,
    0x74, 0x61, 0x7d, 0x66, 0x61, 0x73, 0x3b, 0x5d, 0x66, 0x6d, 0x3c, 0x3f, 0x7b, 0x66, 0x72, 0x36
};


it works, but if i try to create the aesKey array from hex values readed from file, it crash.

any ideas?

additional information copied from non-solution below
this is how i read the last 32 byte from my file:

C#
char *chiavegiusta;
inFile.open(filename, ios::binary);
inFile.seekg(-32, ios::end);
inFile.read((char *)chiavegiusta, 32);
inFile.close();


my problem is how to create an hex array from these values.
Posted
Updated 4-Jun-14 1:55am
v2
Comments
OriginalGriff 4-Jun-14 6:41am    
Without seeing your code? Not a lot we can do to improve it, is there?

But...please don't tell me that you are storing the decryption key as the last 32 bytes of the encrypted file? Because if you are...it defeats the whole idea of encryption.

Quote:
any ideas?
Yes, probably your program doesn't read correctly the numbers form the file. However, you should post the actual code, in order to get better help.

[update]
You never allocated memory for the data. change from
C
char *chiavegiusta;

to
C
unsigned char chiavegiusta[32];

[/update]
 
Share this answer
 
v2
this is how i read the last 32 byte from my file:

C#
char *chiavegiusta;
    inFile.open(filename, ios::binary);
    inFile.seekg(-32, ios::end);
    inFile.read((char *)chiavegiusta, 32);
    inFile.close();


my problem is how to create an hex array from these values.
 
Share this answer
 
Comments
Richard MacCutchan 4-Jun-14 7:23am    
1. Don't post further information as a Solution; edit your question and add it there.
2. You are reading into a character array that does not exist; you have declared a pointer, but it does not point to anything. BTW it would be better to declare it as unsigned char to ensure you do not corrupt the values.
3. There is nothing to convert, when you have read in the 32 bytes that is your array.
4. As mentioned elsewhere, it is a really bad idea to store the key inside the file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900