question about in out parameter



 DEVELOP > c-Plus-Plus > question about in out parameter

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "p_hose"
Date: 17 Nov 2003 04:03:39 AM
Object: question about in out parameter
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");
.

User: "Jack Klein"

Title: Re: question about in out parameter 17 Nov 2003 04:37:02 AM
On 17 Nov 2003 02:03:39 -0800,
(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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER