1 |
/* wptSymEnc.cpp - Symmetric encryption support |
/* wptSymEnc.cpp - Symmetric encryption support |
2 |
* Copyright (C) 2002, 2003, 2004, 2005 Timo Schulz |
* Copyright (C) 2002-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
23 |
#endif |
#endif |
24 |
|
|
25 |
#include <windows.h> |
#include <windows.h> |
|
#include <windows.h> |
|
26 |
|
|
27 |
#include "wptGPG.h" |
#include "wptGPG.h" |
28 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
59 |
|
|
60 |
/* Perform symmetric encryption on the current clipboard data. |
/* Perform symmetric encryption on the current clipboard data. |
61 |
Return 0 for success. */ |
Return 0 for success. */ |
62 |
int |
gpgme_error_t |
63 |
gpg_encrypt_symmetric (void) |
gpg_clip_sym_encrypt (void) |
64 |
{ |
{ |
65 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
66 |
gpgme_data_t plain=NULL; |
gpgme_data_t plain=NULL; |
69 |
char *pass = NULL; |
char *pass = NULL; |
70 |
int cancel = 0; |
int cancel = 0; |
71 |
|
|
72 |
pass = request_passphrase2 (_("Symmetric Encryption"), 0, &cancel); |
pass = request_passphrase2 (_("Symmetric Encryption"), |
73 |
|
PASSDLG_NOTEMPTY, &cancel); |
74 |
if (cancel) |
if (cancel) |
75 |
return 0; |
return 0; |
76 |
rc = gpgme_new (&ctx); |
rc = gpgme_new (&ctx); |
81 |
goto leave; |
goto leave; |
82 |
rc = gpgme_data_new (&ciph); |
rc = gpgme_data_new (&ciph); |
83 |
gpgme_set_armor (ctx, 1); |
gpgme_set_armor (ctx, 1); |
84 |
|
gpgme_set_textmode (ctx, 1); |
85 |
|
|
86 |
gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass); |
gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass); |
87 |
|
|
88 |
rc = gpgme_op_encrypt (ctx, NULL, (gpgme_encrypt_flags_t)0, plain, ciph); |
rc = gpgme_op_encrypt (ctx, NULL, (gpgme_encrypt_flags_t)0, plain, ciph); |
89 |
if (rc) |
if (rc) |
90 |
msg_box (NULL, gpgme_strerror (rc), _("Symmetric Encryption"), MB_ERR); |
msg_box (NULL, gpgme_strerror (rc), _("Symmetric Encryption"), MB_ERR); |
91 |
else { |
else { |
101 |
gpgme_data_release (ciph); |
gpgme_data_release (ciph); |
102 |
gpgme_release (ctx); |
gpgme_release (ctx); |
103 |
sfree_if_alloc (pass); |
sfree_if_alloc (pass); |
104 |
return rc? WPTERR_GENERAL : 0; |
return rc; |
105 |
} |
} |