-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
minisample.c
54 lines (50 loc) · 1.09 KB
/
minisample.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
@file
@brief mini MS Office Crypt DLL sample
@author herumi
Copyright (C) 2016 Cybozu Labs, Inc., all rights reserved.
*/
#include "msoc.h"
#include <stdio.h>
#include <string.h>
void usage()
{
const char *s =
"how to use\n"
"minisample enc <inFile> <outFile> <pass>\n"
"minisample dec <inFile> <outFile> <pass>\n";
printf("%s", s);
exit(1);
}
int main(int argc, char **argv)
{
int err = 0;
const char *mode = NULL;
const char *inFile = NULL;
const char *outFile = NULL;
const char *pass = NULL;
argc--, argv++;
if (argc != 4) {
usage();
}
mode = argv[0];
inFile = argv[1];
outFile = argv[2];
pass = argv[3];
printf("enc in=%s, out=%s, pass=%s\n", inFile, outFile, pass);
if (strcmp(mode, "enc") == 0) {
err = MSOC_encryptA(outFile, inFile, pass, NULL);
} else if (strcmp(mode, "dec") == 0) {
err = MSOC_decryptA(outFile, inFile, pass, NULL);
} else {
printf("base mode=%s\n", mode);
usage();
}
if (err != MSOC_NOERR) {
printf("ERR %s\n", MSOC_getErrMessage(err));
return 1;
} else {
puts("ok");
}
return 0;
}