Index: libabac/abac.h
===================================================================
--- libabac/abac.h	(revision bfaec489bf2d39e473f22553fa04934b7c3e5d81)
+++ libabac/abac.h	(revision a02c8495bfd5c19c5c9dc455b9486310f44e2928)
@@ -90,4 +90,7 @@
 // load an X.509 private key from a file
 int abac_id_privkey_from_file(abac_id_t *id, char *filename);
+
+// load an X.509 private key from a chunk
+int abac_id_privkey_from_chunk(abac_id_t *id, abac_chunk_t chunk);
 
 // generate an ID
Index: libabac/abac.hh
===================================================================
--- libabac/abac.hh	(revision bfaec489bf2d39e473f22553fa04934b7c3e5d81)
+++ libabac/abac.hh	(revision a02c8495bfd5c19c5c9dc455b9486310f44e2928)
@@ -292,5 +292,5 @@
                 m_id = abac_id_from_chunk(chunk);
                 if (m_id == NULL)
-                    throw std::invalid_argument("Could not load ID certificate with abac_chunk_t");
+                    throw std::invalid_argument("Could not load ID certificate with a chunk");
             }
 /***
@@ -310,8 +310,15 @@
             }
 /***
-f  void id_load_privkey_file(char *)
+f  void load_privkey(char *)
      loads the private key associated with the ID credential,
      will throw an exception if the key cannot be loaded
      (C:abac_id_privkey_from_file)
+f  void load_privkey_chunk(abac_chunk_t)
+     loads the private key associated with the ID credential,
+     will throw an exception if the key cannot be loaded
+     (C:abac_id_privkey_from_chunk)
+f  int has_privkey()
+     check to see if there is a privkey in this ID
+     (C:abac_id_has_privkey)
 ***/
             void load_privkey(char *filename) {
@@ -320,5 +327,13 @@
                     throw std::invalid_argument("Could not load private key");
             }
-
+            void load_privkey_chunk(abac_chunk_t chunk) {
+                int ret = abac_id_privkey_from_chunk(m_id, chunk);
+                if (ret != ABAC_SUCCESS)
+                    throw std::invalid_argument("Could not load private key with a chunk");
+            }
+            int has_privkey() {
+                int ret= abac_id_has_privkey(m_id);
+                return ret;
+            }
 /***
 f  char *keyid()
@@ -338,7 +353,7 @@
 f  void write_cert(string &)
      writes a PEM-encoded certificate to a file named in string
-f  void write_cert_file(string &)
+f  void write_cert_file(const char *)
      writes a PEM-encoded certificate to a file
-f  void write_cert_name(string &)
+f  void write_cert_name(const char *)
      writes a PEM-encoded certificate to a file
      (added to support original libcreddy users)
@@ -346,5 +361,5 @@
             void write_cert(FILE *out) { abac_id_write_cert(m_id, out); }
             void write_cert(const std::string &name) {
-                FILE *out = fopen(name.c_str(), "w");
+                FILE *out = fopen(name.c_str(), "a+");
                 if (out == NULL)
                     throw std::invalid_argument("Could not open certificate file for writing");
@@ -374,7 +389,7 @@
 f  void write_privkey(string &)
      writes a private key to file named in string
-f  void write_privkey_file(string &)
+f  void write_privkey_file(const char *)
      writes a private key to a file
-f  void write_privkey_name(string &)
+f  void write_privkey_name(const char *)
      writes a private key to a file
      (added to support original libcreddy users)
@@ -385,5 +400,5 @@
             }
             void write_privkey(const std::string &name) {
-                FILE *out = fopen(name.c_str(), "w");
+                FILE *out = fopen(name.c_str(), "a+");
                 if (out == NULL)
                     throw std::invalid_argument("Could not open privkey file for writing");
Index: libabac/abac_id.c
===================================================================
--- libabac/abac_id.c	(revision bfaec489bf2d39e473f22553fa04934b7c3e5d81)
+++ libabac/abac_id.c	(revision a02c8495bfd5c19c5c9dc455b9486310f44e2928)
@@ -156,4 +156,23 @@
 }
 
+int abac_id_privkey_from_chunk(abac_id_t *id, abac_chunk_t chunk) {
+    assert(id != NULL);
+
+    EVP_PKEY *key=abac_load_privkey_from_chunk(chunk.ptr, chunk.len);
+    if (key == NULL) return ABAC_FAILURE;
+
+/* needs to make sure that the key matches up with the id */
+    /* extract the pub key from the id */
+    EVP_PKEY *pubkey=extract_pubkey_from_cert(id->cert);
+    /* cmp will just compare the pub key part of the key to see
+       if they are the same */
+    if(!EVP_PKEY_cmp(pubkey, key)) {
+        fprintf(stderr,"wrong private key for the cert!!\n");
+        return ABAC_FAILURE;
+    }
+    id->key = key;
+    return ABAC_SUCCESS;
+}
+
 /**
  * Generate an ID with the specified CN and validity.
Index: libabac/abac_openssl.c
===================================================================
--- libabac/abac_openssl.c	(revision bfaec489bf2d39e473f22553fa04934b7c3e5d81)
+++ libabac/abac_openssl.c	(revision a02c8495bfd5c19c5c9dc455b9486310f44e2928)
@@ -352,4 +352,23 @@
 }
 
+EVP_PKEY *abac_load_privkey_from_chunk(unsigned char *chunk_ptr, int chunk_len)
+{
+    EVP_PKEY *nkey=NULL;
+    BIO *mbio=BIO_new(BIO_s_mem());
+
+    BIO_write(mbio,chunk_ptr,chunk_len);
+    BIO_flush(mbio);
+
+    PEM_read_bio_PrivateKey(mbio,&nkey,NULL,NULL);
+
+    BIO_free_all(mbio);
+
+    if (nkey == NULL) {
+        ERR_print_errors_fp (stderr);
+        return NULL;
+    }
+    return nkey;
+}
+
 EVP_PKEY *abac_load_privkey_from_fp(FILE *fp)
 {
Index: libabac/abac_openssl.h
===================================================================
--- libabac/abac_openssl.h	(revision bfaec489bf2d39e473f22553fa04934b7c3e5d81)
+++ libabac/abac_openssl.h	(revision a02c8495bfd5c19c5c9dc455b9486310f44e2928)
@@ -21,4 +21,5 @@
 X509 *abac_load_id_from_fp(FILE *);
 EVP_PKEY *abac_load_privkey_from_fp(FILE *);
+EVP_PKEY *abac_load_privkey_from_chunk(unsigned char *, int);
 X509 *abac_load_id_from_chunk(unsigned char *, int);
 int abac_write_id_to_fp(X509 *cert, FILE *fp);
