#include "KremSDK.h"
#include <string.h>
#include <stdio.h>
#include <direct.h>
#define ARG_PASSWORD 1
#define ARG_ARCHIVENAME 2
#define ARG_FILE1 3
void main(int argc, char *argv[ ], char *envp[ ]) {
if (argc < 3+1) {
printf("You must invoke example as follows: 'example.exe password archivename file1 [file2] [file3]...'\n");
return;
}
else {
char pszCurDir[256], pszFilename[256];
int x;
int r;
_getcwd(pszCurDir,sizeof(pszCurDir));
InitKremlinSDK();
r = ArchiveWriteInit(argv[ARG_ARCHIVENAME],argv[ARG_PASSWORD],strlen(argv[ARG_PASSWORD]),
SDK_ALGORITHM_BLOWFISH,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,pszCurDir,strlen(pszCurDir),
SDK_KEYLENGTH_INFINITE,TRUE,TRUE);
if (r != SDK_SUCCESS){
printf("Error: %s\n",GetErrorText(r));
return;
}
printf("Archive %s created\n",argv[ARG_ARCHIVENAME]);
/* We're using compression, so the archive will never be a random access
archive. Just do this for pedantic completeness */
if (ArchiveRandomAccess()) {
for (x=ARG_FILE1;x<argc-ARG_FILE1;x++)
ArchiveAddIndexFilename(argv[x]);
}
for (x=ARG_FILE1;x<argc;x++) {
/* We need to pass ArchiveAddFile a full path (i.e. C:\dir\test.txt
so we append the current directory */
strcpy(pszFilename,pszCurDir);
strcat(pszFilename,"\\");
strcat(pszFilename,argv[x]);
r = ArchiveAddFile(pszFilename);
if (r == SDK_SUCCESS)
printf("File %s added to encrypted archive\n",argv[x]);
else
printf("Error: %s\n",GetErrorText(r));
}
ArchiveKill();
KillKremlinSDK();
}
}