compilation of ms crypto api program
From: Ashok (ashokraj36_at_yahoo.com)
Date: 06/19/03
- Next message: Brian Gladman: "Re: More LTC timings..."
- Previous message: Richard Heathfield: "Re: Techincal Error in Steven Levy's "Crypto""
- Next in thread: Sisyphus: "Re: compilation of ms crypto api program"
- Reply: Sisyphus: "Re: compilation of ms crypto api program"
- Reply: Russ Lyttle: "Re: compilation of ms crypto api program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 18 Jun 2003 23:21:25 -0700
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)
------------------------------------------------------------------------------
- Next message: Brian Gladman: "Re: More LTC timings..."
- Previous message: Richard Heathfield: "Re: Techincal Error in Steven Levy's "Crypto""
- Next in thread: Sisyphus: "Re: compilation of ms crypto api program"
- Reply: Sisyphus: "Re: compilation of ms crypto api program"
- Reply: Russ Lyttle: "Re: compilation of ms crypto api program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|