Re: compilation of ms crypto api program
From: Sisyphus (kalinabears_at_hdc.com.au)
Date: 06/19/03
- Next message: Timoleon: "Schneier is a press-whore?"
- Previous message: John E. Hadstate: "Re: what is a hash ?"
- In reply to: Ashok: "compilation of ms crypto api program"
- Next in thread: Erwann ABALEA: "Re: compilation of ms crypto api program"
- Reply: Erwann ABALEA: "Re: compilation of ms crypto api program"
- Reply: Ashok: "Re: compilation of ms crypto api program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Thu, 19 Jun 2003 22:33:39 +1000
"Ashok" <ashokraj36@yahoo.com> wrote in message
news:548b67bf.0306182221.2e9c5d70@posting.google.com...
> Dear Group,
>
> I am a newbie to Crypto programming, I tried compiling following
> program using MS VC++ 6.0 on windows2000-sp3+windows high encryption
> pack. but my compilation is not successful, and got about 18 erros,
> can any one help me resolve the same
>
> Thanks in advance,
> Ashok
>
> -----------------------------
> program .......
>
>
>
> # include <wincrypt.h>
> # include <winerror.h>
> # include <stdio.h>
> # include <windows.h>
>
> const OUT_BUFFER_SIZE = 2048+64; // extra padding
> const IN_BUFFER_SIZE = 2048;
>
> void main(int argc, char * argv[])
> {
> HANDLE hInFile, hOutFile;
> BYTE pbBuffer[2048+64];//OUT_BUFFER_SIZE];
>
> BOOL finished;
> HCRYPTPROV hProvider = 0;
> HCRYPTKEY hKey = 0;
> HCRYPTKEY hExchangeKey = 0;
> DWORD dwByteCount, dwBytesWritten;
>
> if (argc != 3) {
> printf("Usage: ENCRYPT infile outfile\n");
> exit(0);
> }
>
> // Get handle for the default provider (use RSA encryption).
> CryptAcquireContext(&hProvider, NULL, NULL, PROV_DSS_DH, 0);
>
> // Open infile and create outfile.
> HInFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ,
> NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
> hOutFile = CreateFile(argv[2], GENERIC_WRITE, FILE_SHARE_READ,
> NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
>
>
> // Generate a random key (in "simple blob" format).
> CryptGetUserKey(hProvider, AT_KEYEXCHANGE, &hExchangeKey);
> CryptGenKey(hProvider, CALG_RC2, CRYPT_EXPORTABLE, &hKey);
>
> // The first call to ExportKey with NULL gets the key size.
> dwByteCount=0;
> CryptExportKey(hKey, hExchangeKey, SIMPLEBLOB, 0, NULL,
> &dwByteCount);
> CryptExportKey(hKey, hExchangeKey, SIMPLEBLOB, 0, pbBuffer,
> &dwByteCount);
>
> // Write size of key blob, then key blob itself, to output
> file.
> WriteFile(hOutFile, &dwByteCount, sizeof(dwByteCount),
> &dwBytesWritten, NULL);
> WriteFile(hOutFile, pbBuffer, dwByteCount, &dwBytesWritten,
> NULL);
>
> // Now, read data in, encrypt it, and write encrypted data to
> output.
> do
> {
> ReadFile(hInFile, pbBuffer,
> IN_BUFFER_SIZE,&dwByteCount,NULL);
> finished = (dwByteCount < IN_BUFFER_SIZE);
> CryptEncrypt(hKey, 0, finished, 0, pbBuffer,
> &dwByteCount, OUT_BUFFER_SIZE);
> WriteFile(hOutFile, pbBuffer, dwByteCount,
> &dwBytesWritten, NULL);
> } while (!finished);
>
> // Clean up: release handles, close files.
> CryptDestroyKey(hKey);
> CryptDestroyKey(hExchangeKey);
>
> CryptReleaseContext(hProvider, 0);
> CloseHandle(hInFile);
> CloseHandle(hOutFile);
> return(0);
> }
> -----------------------------------------
>
> Errors .............
>
> --------------------Configuration: Cpp1 - Win32
> Debug--------------------
> Compiling...
> Cpp1.c
> D:\PSR\MSVC\Cpp1.c(16) : error C2065: 'HCRYPTPROV' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(16) : error C2146: syntax error : missing ';'
> before identifier 'hProvider'
> D:\PSR\MSVC\Cpp1.c(16) : error C2065: 'hProvider' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(17) : error C2065: 'HCRYPTKEY' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(17) : error C2146: syntax error : missing ';'
> before identifier 'hKey'
> D:\PSR\MSVC\Cpp1.c(17) : error C2065: 'hKey' : undeclared identifier
> D:\PSR\MSVC\Cpp1.c(18) : error C2146: syntax error : missing ';'
> before identifier 'hExchangeKey'
> D:\PSR\MSVC\Cpp1.c(18) : error C2065: 'hExchangeKey' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(19) : error C2275: 'DWORD' : illegal use of this
> type as an expression
> d:\program files\microsoft visual
> studio\vc98\include\windef.h(141) : see declaration of 'DWORD'
> D:\PSR\MSVC\Cpp1.c(19) : error C2146: syntax error : missing ';'
> before identifier 'dwByteCount'
> D:\PSR\MSVC\Cpp1.c(19) : error C2065: 'dwByteCount' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(19) : error C2065: 'dwBytesWritten' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(27) : warning C4013: 'CryptAcquireContext'
> undefined; assuming extern returning int
> D:\PSR\MSVC\Cpp1.c(27) : error C2065: 'PROV_DSS_DH' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(30) : error C2065: 'HInFile' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(30) : warning C4047: '=' : 'int ' differs in levels
> of indirection from 'void *'
> D:\PSR\MSVC\Cpp1.c(35) : warning C4013: 'CryptGetUserKey' undefined;
> assuming extern returning int
> D:\PSR\MSVC\Cpp1.c(35) : error C2065: 'AT_KEYEXCHANGE' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(36) : warning C4013: 'CryptGenKey' undefined;
> assuming extern returning int
> D:\PSR\MSVC\Cpp1.c(36) : error C2065: 'CALG_RC2' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(36) : error C2065: 'CRYPT_EXPORTABLE' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(40) : warning C4013: 'CryptExportKey' undefined;
> assuming extern returning int
> D:\PSR\MSVC\Cpp1.c(40) : error C2065: 'SIMPLEBLOB' : undeclared
> identifier
> D:\PSR\MSVC\Cpp1.c(52) : warning C4013: 'CryptEncrypt' undefined;
> assuming extern returning int
> D:\PSR\MSVC\Cpp1.c(57) : warning C4013: 'CryptDestroyKey' undefined;
> assuming extern returning int
> D:\PSR\MSVC\Cpp1.c(60) : warning C4013: 'CryptReleaseContext'
> undefined; assuming extern returning int
> D:\PSR\MSVC\Cpp1.c(63) : warning C4098: 'main' : 'void' function
> returning a value
> Error executing cl.exe.
>
> Cpp1.obj - 18 error(s), 9 warning(s)
>
>
> --------------------------------------------------------------------------
---- Hi, These are C programming issues and, as such, have nothing to do with this newsgroup. Anyway :-) ........ 'main()' should not return a value (because you have specified void) - so delete "return(0);" at the end. If you: # include "\your_path_to\ATL\SRC\STDAFX.H" the typedefs in wincrypt.h are not ignored and most of those errors disappear. Somewhere in there you wrote 'hInFile' as 'HInFile'. You need to correct that typo. There was also a couple of instances where comments extended onto the next line - probably just a case of wrapping - but if you're source contains those same errors then you'll need to correct them. After that I found it at least compiled, though 'encrypt infile outfile' merely copied infile to outfile (no sign of encryption). Haven't looked at reasons for that - maybe it's because I haven't got the "windows high encryption pack". Hth. Cheers, Rob
- Next message: Timoleon: "Schneier is a press-whore?"
- Previous message: John E. Hadstate: "Re: what is a hash ?"
- In reply to: Ashok: "compilation of ms crypto api program"
- Next in thread: Erwann ABALEA: "Re: compilation of ms crypto api program"
- Reply: Erwann ABALEA: "Re: compilation of ms crypto api program"
- Reply: Ashok: "Re: compilation of ms crypto api program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|