DER encoding: implement Certificate::encode.
diff --git a/Makefile.am b/Makefile.am
index 89c5386..f2e717f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -142,6 +142,7 @@
   ndn-cpp/transport/tcp-transport.cpp \
   ndn-cpp/transport/transport.cpp \
   ndn-cpp/transport/udp-transport.cpp \
+  ndn-cpp/util/blob-stream.hpp \
   ndn-cpp/util/blob.cpp \
   ndn-cpp/util/changed-event.cpp ndn-cpp/util/changed-event.hpp \
   ndn-cpp/util/dynamic-uint8-vector.cpp ndn-cpp/util/dynamic-uint8-vector.hpp \
diff --git a/Makefile.in b/Makefile.in
index 5a8aa9d..387f29d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -693,6 +693,7 @@
   ndn-cpp/transport/tcp-transport.cpp \
   ndn-cpp/transport/transport.cpp \
   ndn-cpp/transport/udp-transport.cpp \
+  ndn-cpp/util/blob-stream.hpp \
   ndn-cpp/util/blob.cpp \
   ndn-cpp/util/changed-event.cpp ndn-cpp/util/changed-event.hpp \
   ndn-cpp/util/dynamic-uint8-vector.cpp ndn-cpp/util/dynamic-uint8-vector.hpp \
diff --git a/ndn-cpp/security/certificate/certificate.cpp b/ndn-cpp/security/certificate/certificate.cpp
index b41b739..90010b3 100644
--- a/ndn-cpp/security/certificate/certificate.cpp
+++ b/ndn-cpp/security/certificate/certificate.cpp
@@ -17,6 +17,7 @@
 #include "../../encoding/der/visitor/print-visitor.hpp"
 #endif
 #include "../../util/logging.hpp"
+#include "../../util/blob-stream.hpp"
 #include "../../c/util/time.h"
 #include <ndn-cpp/security/certificate/certificate.hpp>
 
@@ -66,7 +67,6 @@
     return false;
 }
 
-#if 0
 void
 Certificate::encode()
 {
@@ -100,15 +100,13 @@
     }
 
   blob_stream blobStream;
-  OutputIterator& start = reinterpret_cast<OutputIterator&>(blobStream);
+  der::OutputIterator& start = reinterpret_cast<der::OutputIterator&>(blobStream);
 
   root->encode(start);
 
-  shared_ptr<Blob> blob = blobStream.buf();
-  Content content(blob->buf(), blob->size());
-  setContent(content);
+  shared_ptr<std::vector<uint8_t> > blob = blobStream.buf();
+  setContent(blob);
 }
-#endif
 
 void 
 Certificate::decode()
diff --git a/ndn-cpp/util/blob-stream.hpp b/ndn-cpp/util/blob-stream.hpp
new file mode 100644
index 0000000..21a039a
--- /dev/null
+++ b/ndn-cpp/util/blob-stream.hpp
@@ -0,0 +1,67 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_BLOB_STREAM_HPP
+#define NDN_BLOB_STREAM_HPP
+
+// We can use ndnboost::iostreams because this is internal and will not conflict with the application if it uses boost::iostreams.
+#include <ndnboost/iostreams/detail/ios.hpp>
+#include <ndnboost/iostreams/categories.hpp>
+#include <ndnboost/iostreams/stream.hpp>
+#include <ndn-cpp/common.hpp>
+
+namespace ndn {
+
+class blob_append_device {
+public:
+  typedef char  char_type;
+  typedef ndnboost::iostreams::sink_tag category;
+  
+  blob_append_device(std::vector<uint8_t>& container)
+  : container_(container)
+  {
+  }
+  
+  std::streamsize
+  write(const char_type* s, std::streamsize n)
+  {
+    std::copy(s, s+n, std::back_inserter(container_));
+    return n;
+  }
+  
+protected:
+  std::vector<uint8_t>& container_;
+};
+
+/**
+ * This is called "blob_stream" but it doesn't use an ndn::Blob which is immutable.  It uses a pointer to a vector<uint8_t>.
+ * This is inteded for internal library use, not exported in the API.
+ */
+struct blob_stream : public ndnboost::iostreams::stream<blob_append_device>
+{
+  blob_stream()
+    : buffer_(new std::vector<uint8_t>())
+    , device_(*buffer_)
+  {
+    open(device_);
+  }
+
+  ptr_lib::shared_ptr<std::vector<uint8_t> >
+  buf()
+  {
+    flush();
+    return buffer_;
+  }
+
+private:
+  ptr_lib::shared_ptr<std::vector<uint8_t> > buffer_;
+  blob_append_device device_;
+};
+
+}
+
+#endif