summary history branches tags files
commit:65b18e5783b2811069343fc9fc236fd6a5f82383
author:mrmekon
committer:mrmekon
date:Sun Nov 13 19:34:57 2011 -0500
parents:cbd9f515408a37bb4a57cd6eef40cd87b956a810
Added example
diff --git a/examples/01_decrypt/Makefile b/examples/01_decrypt/Makefile
line changes: +7/-0
index 0000000..3b78643
--- /dev/null
+++ b/examples/01_decrypt/Makefile
@@ -0,0 +1,7 @@
+LDFLAGS=`pkg-config --libs simplepgp`
+CFLAGS=`pkg-config --cflags simplepgp`
+
+EXEC=decrypt
+OBJS=decrypt.c
+
+default: $(EXEC)

diff --git a/examples/01_decrypt/ciphertext.pgp b/examples/01_decrypt/ciphertext.pgp
line changes: +0/-0
index 0000000..0c764d6
--- /dev/null
+++ b/examples/01_decrypt/ciphertext.pgp

diff --git a/examples/01_decrypt/decrypt.c b/examples/01_decrypt/decrypt.c
line changes: +62/-0
index 0000000..f78b0f6
--- /dev/null
+++ b/examples/01_decrypt/decrypt.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include <simplepgp.h>
+
+#define SECKEY_BUF 2048
+#define CTEXT_BUF 1024
+
+#define KEY_PASS "test"
+
+int main(int argc, char **argv) {
+  char seckey[SECKEY_BUF];
+  char ctext[CTEXT_BUF];
+  int fd;
+  int seckey_len, ctext_len;
+  spgp_packet_t *pkt;
+
+  printf("simplepgp decrypt example.\n");
+
+  fd = open("test1_sec.pgp", O_RDONLY);
+  if (fd < 0) { perror("seckey open"); return 1; }
+  if ((seckey_len = read(fd, seckey, SECKEY_BUF)) < 0) {
+    perror("seckey read"); return 1;
+  }
+  close(fd);
+
+  fd = open("ciphertext.pgp", O_RDONLY);
+  if (fd < 0) { perror("cipher open"); return 1; }
+  if ((ctext_len = read(fd, ctext, CTEXT_BUF)) < 0) {
+    perror("cipher read"); return 1;
+  }
+  close(fd);
+
+  if (spgp_init() != 0) {
+    fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err()));
+    return 1;
+  }
+
+  spgp_debug_log_set(1);
+
+  pkt = spgp_decode_message(seckey, seckey_len);
+  if (NULL == pkt) {
+    fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err()));
+    return 1;
+  }
+
+  if (spgp_decrypt_all_secret_keys(pkt, KEY_PASS, strlen(KEY_PASS)) != 0) {
+    fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err()));
+    return 1;
+  }
+
+  pkt = spgp_decode_message(ctext, ctext_len);
+  if (NULL == pkt) {
+    fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err()));
+    return 1;
+  }
+
+  spgp_close();
+
+  return 0;
+}

diff --git a/examples/01_decrypt/test1_sec.pgp b/examples/01_decrypt/test1_sec.pgp
line changes: +0/-0
index 0000000..524a4e4
--- /dev/null
+++ b/examples/01_decrypt/test1_sec.pgp