question about in out parameter

P

p_hose

hi
I'm trying to write CPEncrypt function. but i don't change the
content's of the pbData. First it contained the plaintext. But after
encryption i did not write the ciphertext value on it.
thanks.
BOOL WINAPI
CPEncrypt(
IN HCRYPTPROV hProv,
IN HCRYPTKEY hKey,
IN HCRYPTHASH hHash,
IN BOOL fFinal,
IN DWORD dwFlags,
IN OUT LPBYTE pbData,
IN OUT LPDWORD pcbDataLen,
IN DWORD cbBufLen)
{
char *tempData;
tempData=(PBYTE)malloc(strlen(outData));
..
..//pbData (plaintext) is encrypted
..//and ciphertext is written on tempData
..
printf("tempdata degeri %s %d \n",tempData,strlen((char
*)tempData));//in mysample //program i can see these values
memcpy(pbData,tempData,strlen(tempData));//and in this line CSP send
error 0x57 but if i //use hashed data for encryption
//the program is working properly

return true;
}
my sample program code
..
..
..
BYTE *outdata;
outdata=(BYTE *)malloc(100);
size_t size;
size=_msize(outdata);
outdata=(unsigned char*)"selami uekae tubitak";
DWORD len = strlen((const char *)outdata);
if(!CryptEncrypt(hKey, 0,TRUE,0,outdata,&len,(DWORD)size ))
printf("Error %x during CryptEncrypt!\n", GetLastError());
else printf("CryptEncrypt succeed\n");
 
J

Jack Klein

On 17 Nov 2003 02:03:39 -0800, (e-mail address removed) (p_hose)
wrote in comp.lang.c++:

You didn't fix half the mistakes I pointed out when you posted this in
comp.lang.c hours ago.
BOOL WINAPI

There are no keywords BOOL or WINAPI in C++.
CPEncrypt(
IN HCRYPTPROV hProv,
IN HCRYPTKEY hKey,
IN HCRYPTHASH hHash,
IN BOOL fFinal,
IN DWORD dwFlags,
IN OUT LPBYTE pbData,
IN OUT LPDWORD pcbDataLen,
IN DWORD cbBufLen)
{
char *tempData;
tempData=(PBYTE)malloc(strlen(outData));
.
.//pbData (plaintext) is encrypted
.//and ciphertext is written on tempData
.
printf("tempdata degeri %s %d \n",tempData,strlen((char
*)tempData));//in mysample //program i can see these values
memcpy(pbData,tempData,strlen(tempData));//and in this line CSP send
error 0x57 but if i //use hashed data for encryption
//the program is working properly

return true;
}
my sample program code
.
.
.
BYTE *outdata;
outdata=(BYTE *)malloc(100);

You still don't check that the memory allocation succeeded, dipstick.
size_t size;
size=_msize(outdata);
outdata=(unsigned char*)"selami uekae tubitak";

You still create a memory leak by assigning a pointer to a string
literal into the pointer to memory that you allocated.

If you're not going to take advice when you ask for it, go the fsck
away.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top