Click here to Skip to main content
15,886,805 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code that causes error is attached here.

C++
BOOL EncryptFile(
                PCHAR szSource, 
                PCHAR szDestination,
                BYTE* KeyBlob); 

BOOL DecryptFile(
                PCHAR szSource, 
                PCHAR szDestination,
                BYTE* KeyBlob);
int main()
{
BYTE  KeyBlob = NULL;
EncryptFile(szSource, szDestination, &KeyBlob);
DecryptFile(szDestination, szSource, &KeyBlob);
}

when the EncryptFile is returned, the KeyBLob is empty and in the function it has the value set. How to call the keyBlob variable so that it is copied to the memory location
Posted
Updated 7-Jan-16 0:09am
v5
Comments
Jochen Arndt 7-Jan-16 5:36am    
The code snippets makes no sense and should result in compilation errors.

From the function definitions you should pass a pointer to PBYTE.
So it should be

PBYTE KeyBlob = NULL;

assuming that the crypt functions will allocate memory and return the pointer to that memory in KeyBlob.
Richard MacCutchan 7-Jan-16 6:14am    
You have not declared szSource or szDestination let alone initialised them. Jochen already pointed out that KeyBlob is incorrectly declared. And even if they were, your code does nothing.
Aescleal 9-Jan-16 2:32am    
Give us a few more clues about what API you're trying to use. We can guess that source and destination for something called encryptfile would be pathnames but if they are why aren't they const? Likewise what's the point of KeyBlob? Presumably it's a lump of memory containing the crypto key but then you seem to expect something to happen when you call encrypt to set that.

So give us a few more details and someone might be able to give you a decent answer rather than just speculating.

1 solution

it is really easy, but change the interface to PBYTE for clarification
C++
BOOL EncryptFile(
                PBYTE szSource, 
                PBYTE szDestination,
                BYTE* KeyBlob)
{
  for( int i = 0; i < size; i++ ) {   //ensure that i is valid
    szDestination[i]  = szSource[i] & KeayBlob[i]; //some real crypto mechanism is needed
  }
} 

Take a dive into a good pointers tutorial. Tip: run the code with the debugger
 
Share this answer
 

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