-
Notifications
You must be signed in to change notification settings - Fork 9
/
rn_decrypt.c
67 lines (59 loc) · 1.53 KB
/
rn_decrypt.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
/*
**
** Decrypt a RNCryptor Encrypted File, 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,
*decrypted_file = NULL;
unsigned char
*outdata = NULL;
int
outdata_len = 0,
rc;
char
errbuf[BUFSIZ];
if (argc != 3)
{
show_example_usage(argv[0],"file.enc","file.plain");
return(1);
}
password = getenv("RNCPASS");
if (!password)
{
(void) fprintf(stderr,"ERROR: set the password with env variable RNCPASS\n");
return(1);
}
encrypted_file = argv[1];
decrypted_file = argv[2];
memset(errbuf,0,sizeof(errbuf));
rncryptorc_set_debug(1);
outdata = rncryptorc_decrypt_file_with_password(encrypted_file,
RNCRYPTOR3_KDF_ITER,
password,strlen(password),
&outdata_len,
errbuf,sizeof(errbuf)-1);
if (outdata)
{
rc = rncryptorc_write_file(decrypted_file,outdata,outdata_len);
(void) free((char *)outdata);
if (rc == SUCCESS)
{
if (*decrypted_file != '-')
(void) fprintf(stderr,"%s:%d - Decrypted to %s\n",MCFL,decrypted_file);
else
{
(void) fflush(stdout);
}
return(0);
}
}
return(1);
}