-
Notifications
You must be signed in to change notification settings - Fork 9
/
rn_encrypt.c
70 lines (61 loc) · 1.49 KB
/
rn_encrypt.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
**
** Encrypt a file using RNCryptor, Spec v3
** Specification: https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md
**
** Development History:
** - muquit@muquit.com May-19-2015 - first cut
*/
#include "rncryptor_c.h"
int main(int argc,char *argv[])
{
char
*password = NULL,
*encrypted_file = NULL,
*plain_file = NULL;
int
rc;
char
errbuf[BUFSIZ];
unsigned char
*outdata = NULL;
int
outdata_len = 0;
if (argc != 3)
{
show_example_usage(argv[0],"file.plain","file.enc");
return(1);
}
password = getenv("RNCPASS");
if (!password)
{
(void) fprintf(stderr,"ERROR: set the password with env variable RNCPASS\n");
return(1);
}
plain_file = argv[1];
encrypted_file = argv[2];
memset(errbuf,0,sizeof(errbuf));
rncryptorc_set_debug(1);
outdata = rncryptorc_encrypt_file_with_password(plain_file,
RNCRYPTOR3_KDF_ITER,
password,strlen(password),
&outdata_len,
errbuf,
sizeof(errbuf)-1);
if (outdata)
{
rc = rncryptorc_write_file(encrypted_file,outdata,outdata_len);
(void)free((char *)outdata);
if (rc == SUCCESS)
{
(void) fprintf(stderr,"Encrypted file: %s\n",encrypted_file);
return(0);
}
}
else
{
(void) fprintf(stderr,"ERROR: %s\n",errbuf);
return(1);
}
return(0);
}