-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypt.c
59 lines (51 loc) · 1.41 KB
/
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
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <gpgme.h>
#include "routines.h"
const char file_name[] = "encrypted-file";
int main()
{
gpgme_error_t err;
gpgme_ctx_t ctx;
gpgme_data_t cipher, plain;
gpgme_decrypt_result_t result;
init_gpgme();
err = gpgme_new(&ctx);
exit_if_err(err);
init_ctx(ctx, GPGME_PROTOCOL_OPENPGP);
/* start decrypt */
/* If copy is not zero, the whole file is read in at
initialization time and the file is not used anymore
after that. This is the only mode supported currently. */
err = gpgme_data_new_from_file(&cipher, file_name, /* copy */ 1);
exit_if_err(err);
err = gpgme_data_new(&plain);
exit_if_err(err);
err = gpgme_op_decrypt(ctx, cipher, plain);
exit_if_err(err);
result = gpgme_op_decrypt_result(ctx);
if(result->unsupported_algorithm) {
fprintf(stderr, "%s:%d: Unsupported algorithm: %s\n"
"Wrong key usage: %s\n"
"Legacy cipher nomdc: %s\n"
"Is mime: %s\n"
"Is de vs: %s\n"
"File name: %s\n"
"Symkey algo: %s\n",
__FILE__, __LINE__,
result->unsupported_algorithm,
result->wrong_key_usage ? "yes" : "no",
result->legacy_cipher_nomdc ? "yes" : "no",
result->is_mime ? "yes" : "no",
result->is_de_vs ? "yes" : "no",
result->file_name ? result->file_name : "null",
result->symkey_algo);
return 1;
}
loop_read(plain);
gpgme_data_release(cipher);
gpgme_data_release(plain);
gpgme_release(ctx);
return 0;
}