security: Added MemoryIdentityStorage and MemoryPrivateKeyStorage.
diff --git a/ndn-cpp/security/identity/identity-storage.hpp b/ndn-cpp/security/identity/identity-storage.hpp
new file mode 100644
index 0000000..8b06e2a
--- /dev/null
+++ b/ndn-cpp/security/identity/identity-storage.hpp
@@ -0,0 +1,198 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_IDENTITY_STORAGE_HPP
+#define	NDN_IDENTITY_STORAGE_HPP
+
+#include "../../name.hpp"
+#include "../security-common.hpp"
+
+namespace ndn {
+
+class Certificate;
+class Data;
+
+/**
+ * IdentityStorage is a base class for the storage of identity, public keys and certificates. 
+ * Private keys are stored in PrivateKeyStorage.
+ * This is an abstract base class.  A subclass must implement the methods.
+ */
+class IdentityStorage {
+public:
+  /**
+   * The virtual Destructor.
+   */
+  virtual 
+  ~IdentityStorage() {}
+
+  /**
+   * Check if the specified identity already exists.
+   * @param identityName The identity name.
+   * @return true if the identity exists, otherwise false.
+   */
+  virtual bool 
+  doesIdentityExist(const Name& identityName) = 0;
+
+  /**
+   * Add a new identity. An exception will be thrown if the identity already exists.
+   * @param identityName The identity name to be added.
+   */
+  virtual void
+  addIdentity(const Name& identityName) = 0;
+
+  /**
+   * Revoke the identity.
+   * @return true if the identity was revoked, false if not.
+   */
+  virtual bool 
+  revokeIdentity() = 0;
+
+  /**
+   * Generate a name for a new key belonging to the identity.
+   * @param identityName The identity name.
+   * @param useKsk If true, generate a KSK name, otherwise a DSK name.
+   * @return The generated key name.
+   */
+  virtual Name 
+  getNewKeyName(const Name& identityName, bool useKsk) = 0;
+
+  /**
+   * Check if the specified key already exists.
+   * @param keyName The name of the key.
+   * @return true if the key exists, otherwise false.
+   */
+  virtual bool 
+  doesKeyExist(const Name& keyName) = 0;
+
+  /**
+   * Extract the key name from the certificate name.
+   * @param certificateName The certificate name to be processed.
+   */
+  virtual Name 
+  getKeyNameForCertificate(const Name& certificateName) = 0;
+
+  /**
+   * Add a public key to the identity storage.
+   * @param keyName The name of the public key to be added.
+   * @param keyType Type of the public key to be added.
+   * @param publicKeyDer A blob of the public key DER to be added.
+   */
+  virtual void 
+  addKey(const Name& keyName, KeyType keyType, Blob& publicKeyDer) = 0;
+
+  /**
+   * Get the public key DER blob from the identity storage.
+   * @param keyName The name of the requested public key.
+   */
+  virtual Blob
+  getKey(const Name& keyName) = 0;
+
+  /**
+   * Activate a key.  If a key is marked as inactive, its private part will not be used in packet signing.
+   * @param keyName name of the key
+   */
+  virtual void 
+  activateKey(const Name& keyName) = 0;
+
+  /**
+   * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
+   * @param keyName name of the key
+   */
+  virtual void 
+  deactivateKey(const Name& keyName) = 0;
+
+  /**
+   * Check if the specified certificate already exists.
+   * @param certificateName The name of the certificate.
+   * @return true if the certificate exists, otherwise false.
+   */
+  virtual bool
+  doesCertificateExist(const Name& certificateName) = 0;
+
+  /**
+   * Add a certificate to the identity storage.
+   * @param certificate The certificate to be added.
+   */
+  virtual void 
+  addCertificate(const Certificate& certificate) = 0;
+
+  /**
+   * Get a certificate from the identity storage.
+   * @param certificateName The name of the requested certificate.
+   * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
+   * @return The requested certificate.
+   */
+  virtual ptr_lib::shared_ptr<Data> 
+  getCertificate(const Name &certificateName, bool allowAny = false) = 0;
+
+
+  /*****************************************
+   *           Get/Set Default             *
+   *****************************************/
+
+  /**
+   * Get the default identity. 
+   * @param return The name of default identity.
+   */
+  virtual Name 
+  getDefaultIdentity() = 0;
+
+  /**
+   * Get the default key name for the specified identity.
+   * @param identityName The identity name.
+   * @return The default key name.
+   */
+  virtual Name 
+  getDefaultKeyNameForIdentity(const Name& identityName) = 0;
+
+  /**
+   * Get the default certificate name for the specified identity.
+   * @param identityName The identity name.
+   * @return The default certificate name.
+   */
+  Name 
+  getDefaultCertificateNameForIdentity(const Name& identityName)
+  {
+    return getDefaultCertificateNameForKey(getDefaultKeyNameForIdentity(identityName));
+  }
+
+  /**
+   * Get the default certificate name for the specified key.
+   * @param keyName The key name.
+   * @return The default certificate name.
+   */
+  virtual Name 
+  getDefaultCertificateNameForKey(const Name& keyName) = 0;
+
+  /**
+   * Set the default identity.
+   * @param identityName The default identity name.
+   */
+  virtual void 
+  setDefaultIdentity(const Name& identityName) = 0;
+
+  /**
+   * Set the default key name for the specified identity.
+   * @param keyName The key name.
+   * @param identityName (optional) The identity name to check the keyName.
+   */
+  virtual void 
+  setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityName = Name()) = 0;
+
+  /**
+   * Set the default key name for the specified identity.
+   * @param keyName The key name.
+   * @param certificateName The certificate name.
+   */
+  virtual void 
+  setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;  
+};
+
+}
+
+#endif
diff --git a/ndn-cpp/security/identity/memory-identity-storage.cpp b/ndn-cpp/security/identity/memory-identity-storage.cpp
new file mode 100644
index 0000000..a70c339
--- /dev/null
+++ b/ndn-cpp/security/identity/memory-identity-storage.cpp
@@ -0,0 +1,177 @@
+/* -*- 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.
+ */
+
+#include <stdexcept>
+#include "memory-identity-storage.hpp"
+
+using namespace std;
+using namespace ndn::ptr_lib;
+
+namespace ndn {
+
+MemoryIdentityStorage::~MemoryIdentityStorage()
+{
+}
+
+bool 
+MemoryIdentityStorage::doesIdentityExist(const Name& identityName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::doesIdentityExist not implemented");
+#endif
+}
+
+void
+MemoryIdentityStorage::addIdentity(const Name& identityName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::addIdentity not implemented");
+#endif
+}
+
+bool 
+MemoryIdentityStorage::revokeIdentity()
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::revokeIdentity not implemented");
+#endif
+}
+
+Name 
+MemoryIdentityStorage::getNewKeyName(const Name& identityName, bool useKsk)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::getNewKeyName not implemented");
+#endif
+}
+
+bool 
+MemoryIdentityStorage::doesKeyExist(const Name& keyName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::doesKeyExist not implemented");
+#endif
+}
+
+Name 
+MemoryIdentityStorage::getKeyNameForCertificate(const Name& certificateName)
+{
+  int i = certificateName.getComponentCount() - 1;
+
+  for (; i >= 0; --i) {
+    if(certificateName.getComponent(i).toEscapedString() == string("ID-CERT"))
+      break; 
+  }
+    
+  return certificateName.getSubName(0, i);
+}
+
+void 
+MemoryIdentityStorage::addKey(const Name& keyName, KeyType keyType, Blob& publicKeyDer)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::addKey not implemented");
+#endif
+}
+
+Blob
+MemoryIdentityStorage::getKey(const Name& keyName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::getKey not implemented");
+#endif
+}
+
+void 
+MemoryIdentityStorage::activateKey(const Name& keyName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::activateKey not implemented");
+#endif
+}
+
+void 
+MemoryIdentityStorage::deactivateKey(const Name& keyName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::deactivateKey not implemented");
+#endif
+}
+
+bool
+MemoryIdentityStorage::doesCertificateExist(const Name& certificateName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::doesCertificateExist not implemented");
+#endif
+}
+
+void 
+MemoryIdentityStorage::addCertificate(const Certificate& certificate)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::addCertificate not implemented");
+#endif
+}
+
+ptr_lib::shared_ptr<Data> 
+MemoryIdentityStorage::getCertificate(const Name &certificateName, bool allowAny)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::getCertificate not implemented");
+#endif
+}
+
+Name 
+MemoryIdentityStorage::getDefaultIdentity()
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::getDefaultIdentity not implemented");
+#endif
+}
+
+Name 
+MemoryIdentityStorage::getDefaultKeyNameForIdentity(const Name& identityName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::getDefaultKeyNameForIdentity not implemented");
+#endif
+}
+
+Name 
+MemoryIdentityStorage::getDefaultCertificateNameForKey(const Name& keyName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::getDefaultCertificateNameForKey not implemented");
+#endif
+}
+
+void 
+MemoryIdentityStorage::setDefaultIdentity(const Name& identityName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::setDefaultIdentity not implemented");
+#endif
+}
+
+void 
+MemoryIdentityStorage::setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityName)
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::setDefaultKeyNameForIdentity not implemented");
+#endif
+}
+
+void 
+MemoryIdentityStorage::setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName)  
+{
+#if 1
+  throw std::runtime_error("MemoryIdentityStorage::setDefaultCertificateNameForKey not implemented");
+#endif
+}
+
+}
diff --git a/ndn-cpp/security/identity/memory-identity-storage.hpp b/ndn-cpp/security/identity/memory-identity-storage.hpp
new file mode 100644
index 0000000..535aa76
--- /dev/null
+++ b/ndn-cpp/security/identity/memory-identity-storage.hpp
@@ -0,0 +1,182 @@
+/* -*- 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_MEMORY_IDENTITY_STORAGE_HPP
+#define	NDN_MEMORY_IDENTITY_STORAGE_HPP
+
+#include "identity-storage.hpp"
+
+namespace ndn {
+
+/**
+ * MemoryIdentityStorage extends IdentityStorage and implements its methods to store identity, public key and certificate objects in memory.
+ * The application must get the objects through its own means and add the objects to the MemoryIdentityStorage object.
+ * To use permanent file-based storage, see BasicIdentityStorage.
+ */
+class MemoryIdentityStorage : public IdentityStorage {
+public:
+  /**
+   * The virtual Destructor.
+   */
+  virtual 
+  ~MemoryIdentityStorage();
+
+  /**
+   * Check if the specified identity already exists.
+   * @param identityName The identity name.
+   * @return true if the identity exists, otherwise false.
+   */
+  virtual bool 
+  doesIdentityExist(const Name& identityName);
+
+  /**
+   * Add a new identity. An exception will be thrown if the identity already exists.
+   * @param identityName The identity name to be added.
+   */
+  virtual void
+  addIdentity(const Name& identityName);
+
+  /**
+   * Revoke the identity.
+   * @return true if the identity was revoked, false if not.
+   */
+  virtual bool 
+  revokeIdentity();
+
+  /**
+   * Generate a name for a new key belonging to the identity.
+   * @param identityName The identity name.
+   * @param useKsk If true, generate a KSK name, otherwise a DSK name.
+   * @return The generated key name.
+   */
+  virtual Name 
+  getNewKeyName(const Name& identityName, bool useKsk);
+
+  /**
+   * Check if the specified key already exists.
+   * @param keyName The name of the key.
+   * @return true if the key exists, otherwise false.
+   */
+  virtual bool 
+  doesKeyExist(const Name& keyName);
+
+  /**
+   * Extract the key name from the certificate name.
+   * @param certificateName The certificate name to be processed.
+   */
+  virtual Name 
+  getKeyNameForCertificate(const Name& certificateName);
+
+  /**
+   * Add a public key to the identity storage.
+   * @param keyName The name of the public key to be added.
+   * @param keyType Type of the public key to be added.
+   * @param publicKeyDer A blob of the public key DER to be added.
+   */
+  virtual void 
+  addKey(const Name& keyName, KeyType keyType, Blob& publicKeyDer);
+
+  /**
+   * Get the public key DER blob from the identity storage.
+   * @param keyName The name of the requested public key.
+   */
+  virtual Blob
+  getKey(const Name& keyName);
+
+  /**
+   * Activate a key.  If a key is marked as inactive, its private part will not be used in packet signing.
+   * @param keyName name of the key
+   */
+  virtual void 
+  activateKey(const Name& keyName);
+
+  /**
+   * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
+   * @param keyName name of the key
+   */
+  virtual void 
+  deactivateKey(const Name& keyName);
+
+  /**
+   * Check if the specified certificate already exists.
+   * @param certificateName The name of the certificate.
+   * @return true if the certificate exists, otherwise false.
+   */
+  virtual bool
+  doesCertificateExist(const Name& certificateName);
+
+  /**
+   * Add a certificate to the identity storage.
+   * @param certificate The certificate to be added.
+   */
+  virtual void 
+  addCertificate(const Certificate& certificate);
+
+  /**
+   * Get a certificate from the identity storage.
+   * @param certificateName The name of the requested certificate.
+   * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
+   * @return The requested certificate.
+   */
+  virtual ptr_lib::shared_ptr<Data> 
+  getCertificate(const Name &certificateName, bool allowAny = false);
+
+
+  /*****************************************
+   *           Get/Set Default             *
+   *****************************************/
+
+  /**
+   * Get the default identity. 
+   * @param return The name of default identity.
+   */
+  virtual Name 
+  getDefaultIdentity();
+
+  /**
+   * Get the default key name for the specified identity.
+   * @param identityName The identity name.
+   * @return The default key name.
+   */
+  virtual Name 
+  getDefaultKeyNameForIdentity(const Name& identityName);
+
+  /**
+   * Get the default certificate name for the specified key.
+   * @param keyName The key name.
+   * @return The default certificate name.
+   */
+  virtual Name 
+  getDefaultCertificateNameForKey(const Name& keyName);
+
+  /**
+   * Set the default identity.
+   * @param identityName The default identity name.
+   */
+  virtual void 
+  setDefaultIdentity(const Name& identityName);
+
+  /**
+   * Set the default key name for the specified identity.
+   * @param keyName The key name.
+   * @param identityName (optional) The identity name to check the keyName.
+   */
+  virtual void 
+  setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityName = Name());
+
+  /**
+   * Set the default key name for the specified identity.
+   * @param keyName The key name.
+   * @param certificateName The certificate name.
+   */
+  virtual void 
+  setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName);  
+};
+
+}
+
+#endif
diff --git a/ndn-cpp/security/identity/memory-private-key-storage.cpp b/ndn-cpp/security/identity/memory-private-key-storage.cpp
new file mode 100644
index 0000000..56054af
--- /dev/null
+++ b/ndn-cpp/security/identity/memory-private-key-storage.cpp
@@ -0,0 +1,119 @@
+/* -*- 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.
+ */
+
+#include "../../c/util/crypto.h"
+#include "../security-exception.hpp"
+#include "memory-private-key-storage.hpp"
+
+using namespace std;
+using namespace ndn::ptr_lib;
+
+namespace ndn {
+
+MemoryPrivateKeyStorage::~MemoryPrivateKeyStorage()
+{
+}
+
+void MemoryPrivateKeyStorage::setKeyPairForKeyName
+  (const Name& keyName, unsigned char *publicKeyDer, size_t publicKeyDerLength, unsigned char *privateKeyDer, 
+   size_t privateKeyDerLength)
+{
+  publicKeyStore_[keyName.toUri()] = PublicKey::fromDer(Blob(publicKeyDer, publicKeyDerLength));
+  privateKeyStore_[keyName.toUri()] = shared_ptr<RsaPrivateKey>(new RsaPrivateKey(privateKeyDer, privateKeyDerLength));
+}
+
+void 
+MemoryPrivateKeyStorage::generateKeyPair(const Name& keyName, KeyType keyType, int keySize)
+{
+#if 1
+  throw std::runtime_error("MemoryPrivateKeyStorage::generateKeyPair not implemented");
+#endif
+}
+
+shared_ptr<PublicKey> 
+MemoryPrivateKeyStorage::getPublicKey(const Name& keyName)
+{
+  map<string, shared_ptr<PublicKey> >::iterator publicKey = publicKeyStore_.find(keyName.toUri());
+  if (publicKey == publicKeyStore_.end())
+    throw SecurityException(string("MemoryPrivateKeyStorage: Cannot find public key ") + keyName.toUri());
+  return publicKey->second;
+}
+
+Blob 
+MemoryPrivateKeyStorage::sign(const unsigned char *data, unsigned int dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm)
+{
+  if (digestAlgorithm != DIGEST_ALGORITHM_SHA256)
+    return Blob();
+
+  unsigned char digest[SHA256_DIGEST_LENGTH];
+  ndn_digestSha256(data, dataLength, digest);
+  // TODO: use RSA_size to get the proper size of the signature buffer.
+  unsigned char signatureBits[1000];
+  unsigned int signatureBitsLength;
+  
+  // Find the private key and sign.
+  map<string, shared_ptr<RsaPrivateKey> >::iterator privateKey = privateKeyStore_.find(keyName.toUri());
+  if (privateKey == privateKeyStore_.end())
+    throw SecurityException(string("MemoryPrivateKeyStorage: Cannot find private key ") + keyName.toUri());
+  if (!RSA_sign(NID_sha256, digest, sizeof(digest), signatureBits, &signatureBitsLength, privateKey->second->getPrivateKey()))
+    throw SecurityException("Error in RSA_sign");
+  
+  return Blob(signatureBits, signatureBitsLength);
+}
+
+Blob 
+MemoryPrivateKeyStorage::decrypt(const Name& keyName, const unsigned char* data, unsigned int dataLength, bool isSymmetric)
+{
+#if 1
+  throw std::runtime_error("MemoryPrivateKeyStorage::decrypt not implemented");
+#endif
+}
+
+Blob
+MemoryPrivateKeyStorage::encrypt(const Name& keyName, const unsigned char* data, unsigned int dataLength, bool isSymmetric)
+{
+#if 1
+  throw std::runtime_error("MemoryPrivateKeyStorage::encrypt not implemented");
+#endif
+}
+
+void 
+MemoryPrivateKeyStorage::generateKey(const Name& keyName, KeyType keyType, int keySize)
+{
+#if 1
+  throw std::runtime_error("MemoryPrivateKeyStorage::generateKey not implemented");
+#endif
+}
+
+bool
+MemoryPrivateKeyStorage::doesKeyExist(const Name& keyName, KeyClass keyClass)
+{
+  if (keyClass == KEY_CLASS_PUBLIC)
+    return publicKeyStore_.find(keyName.toUri()) != publicKeyStore_.end();
+  else if (keyClass == KEY_CLASS_PRIVATE)
+    return privateKeyStore_.find(keyName.toUri()) != privateKeyStore_.end();
+  else
+    // KEY_CLASS_SYMMETRIC not implemented yet.
+    return false;
+}
+
+MemoryPrivateKeyStorage::RsaPrivateKey::RsaPrivateKey(unsigned char *keyDer, size_t keyDerLength)
+{
+  // Use a temporary pointer since d2i updates it.
+  const unsigned char *derPointer = keyDer;
+  privateKey_ = d2i_RSAPrivateKey(NULL, &derPointer, keyDerLength);
+  if (!privateKey_)
+    throw SecurityException("RsaPrivateKey constructor: Error decoding private key DER");
+}
+
+MemoryPrivateKeyStorage::RsaPrivateKey::~RsaPrivateKey()
+{
+  if (privateKey_)
+    RSA_free(privateKey_);
+}
+
+}
diff --git a/ndn-cpp/security/identity/memory-private-key-storage.hpp b/ndn-cpp/security/identity/memory-private-key-storage.hpp
new file mode 100644
index 0000000..d97d2a8
--- /dev/null
+++ b/ndn-cpp/security/identity/memory-private-key-storage.hpp
@@ -0,0 +1,132 @@
+/* -*- 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_MEMORY_PRIVATE_KEY_STORAGE_HPP
+#define	NDN_MEMORY_PRIVATE_KEY_STORAGE_HPP
+
+#include <map>
+#include "private-key-storage.hpp"
+
+struct rsa_st;
+
+namespace ndn {
+
+/**
+ * MemoryPrivateKeyStorage extends PrivateKeyStorage to implement a simple in-memory private key store.  You should
+ * initialize by calling setKeyPairForKeyName.
+ */
+class MemoryPrivateKeyStorage : public PrivateKeyStorage {
+public:
+  /**
+   * The virtual destructor
+   */    
+  virtual 
+  ~MemoryPrivateKeyStorage();
+
+  /**
+   * Set the public and private key for the keyName.
+   * @param keyName The key name.
+   * @param publicKeyDer The public key DER byte array.
+   * @param publicKeyDerLength The length of publicKeyDer.
+   * @param privateKeyDer The private key DER byte array.
+   * @param privateKeyDerLength The length of privateKeyDer.
+   */
+  void setKeyPairForKeyName
+    (const Name& keyName, unsigned char *publicKeyDer, size_t publicKeyDerLength, unsigned char *privateKeyDer, 
+     size_t privateKeyDerLength);
+  
+  /**
+   * Generate a pair of asymmetric keys.
+   * @param keyName The name of the key pair.
+   * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
+   * @param keySize The size of the key pair.
+   */
+  virtual void 
+  generateKeyPair(const Name& keyName, KeyType keyType, int keySize);
+
+  /**
+   * Get the public key
+   * @param keyName The name of public key.
+   * @return The public key.
+   */
+  virtual ptr_lib::shared_ptr<PublicKey> 
+  getPublicKey(const Name& keyName);
+  
+  /**
+   * Fetch the private key for keyName and sign the data, returning a signature Blob.
+   * @param data Pointer to the input byte array.
+   * @param dataLength The length of data.
+   * @param keyName The name of the signing key.
+   * @param digestAlgorithm the digest algorithm.
+   * @return The signature, or a null pointer if signing fails.
+   */  
+  virtual Blob 
+  sign(const unsigned char *data, unsigned int dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
+    
+  /**
+   * Decrypt data.
+   * @param keyName The name of the decrypting key.
+   * @param data The byte to be decrypted.
+   * @param dataLength the length of data.
+   * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
+   * @return The decrypted data.
+   */
+  virtual Blob 
+  decrypt(const Name& keyName, const unsigned char* data, unsigned int dataLength, bool isSymmetric);
+
+  /**
+   * Encrypt data.
+   * @param keyName The name of the encrypting key.
+   * @param data The byte to be encrypted.
+   * @param dataLength the length of data.
+   * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
+   * @return The encrypted data.
+   */
+  virtual Blob
+  encrypt(const Name& keyName, const unsigned char* data, unsigned int dataLength, bool isSymmetric);
+
+  /**
+   * @brief Generate a symmetric key.
+   * @param keyName The name of the key.
+   * @param keyType The type of the key, e.g. KEY_TYPE_AES.
+   * @param keySize The size of the key.
+   */
+  virtual void 
+  generateKey(const Name& keyName, KeyType keyType, int keySize);
+
+  /**
+   * Check if a particular key exists.
+   * @param keyName The name of the key.
+   * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
+   * @return True if the key exists, otherwise false.
+   */
+  virtual bool
+  doesKeyExist(const Name& keyName, KeyClass keyClass);  
+  
+private:
+  /**
+   * RsaPrivateKey is a simple class to hold an RSA private key.
+   */
+  class RsaPrivateKey {
+  public:
+    RsaPrivateKey(unsigned char *keyDer, size_t keyDerLength);
+    
+    ~RsaPrivateKey();
+    
+    struct rsa_st* getPrivateKey() { return privateKey_; }
+    
+  private:
+    struct rsa_st* privateKey_;
+  };
+    
+  std::map<std::string, ptr_lib::shared_ptr<PublicKey> > publicKeyStore_;      /**< The map key is the keyName.toUri() */
+  std::map<std::string, ptr_lib::shared_ptr<RsaPrivateKey> > privateKeyStore_; /**< The map key is the keyName.toUri() */
+};
+
+}
+
+#endif
diff --git a/ndn-cpp/security/identity/private-key-storage.cpp b/ndn-cpp/security/identity/private-key-storage.cpp
deleted file mode 100644
index 06c6445..0000000
--- a/ndn-cpp/security/identity/private-key-storage.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#if 1
-#include <stdexcept>
-#include "../../c/util/crypto.h"
-#endif
-#include "private-key-storage.hpp"
-
-using namespace std;
-
-namespace ndn {
-
-PrivateKeyStorage::~PrivateKeyStorage()
-{
-}
-
-#if 1
-static unsigned char DEFAULT_PRIVATE_KEY_DER[] = {
-0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xe1, 0x7d, 0x30, 0xa7, 0xd8, 0x28, 0xab, 0x1b, 0x84,
-0x0b, 0x17, 0x54, 0x2d, 0xca, 0xf6, 0x20, 0x7a, 0xfd, 0x22, 0x1e, 0x08, 0x6b, 0x2a, 0x60, 0xd1, 0x6c, 0xb7, 0xf5, 0x44,
-0x48, 0xba, 0x9f, 0x3f, 0x08, 0xbc, 0xd0, 0x99, 0xdb, 0x21, 0xdd, 0x16, 0x2a, 0x77, 0x9e, 0x61, 0xaa, 0x89, 0xee, 0xe5,
-0x54, 0xd3, 0xa4, 0x7d, 0xe2, 0x30, 0xbc, 0x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32, 0x82, 0x9f, 0x53, 0xb3, 0x9e, 0x5f,
-0xc1, 0x53, 0x52, 0x3e, 0xac, 0x2e, 0x28, 0x51, 0xa1, 0x16, 0xdb, 0x90, 0xe3, 0x99, 0x7e, 0x88, 0xa4, 0x04, 0x7c, 0x92,
-0xae, 0xd2, 0xe7, 0xd4, 0xe1, 0x55, 0x20, 0x90, 0x3e, 0x3c, 0x6a, 0x63, 0xf0, 0x34, 0xf1, 0x02, 0x41, 0x00, 0x84, 0x5a,
-0x17, 0x6c, 0xc6, 0x3c, 0x84, 0xd0, 0x93, 0x7a, 0xff, 0x56, 0xe9, 0x9e, 0x98, 0x2b, 0xcb, 0x5a, 0x24, 0x4a, 0xff, 0x21,
-0xb4, 0x9e, 0x87, 0x3d, 0x76, 0xd8, 0x9b, 0xa8, 0x73, 0x96, 0x6c, 0x2b, 0x5c, 0x5e, 0xd3, 0xa6, 0xff, 0x10, 0xd6, 0x8e,
-0xaf, 0xa5, 0x8a, 0xcd, 0xa2, 0xde, 0xcb, 0x0e, 0xbd, 0x8a, 0xef, 0xae, 0xfd, 0x3f, 0x1d, 0xc0, 0xd8, 0xf8, 0x3b, 0xf5,
-0x02, 0x7d, 0x02, 0x41, 0x00, 0x8b, 0x26, 0xd3, 0x2c, 0x7d, 0x28, 0x38, 0x92, 0xf1, 0xbf, 0x15, 0x16, 0x39, 0x50, 0xc8,
-0x6d, 0x32, 0xec, 0x28, 0xf2, 0x8b, 0xd8, 0x70, 0xc5, 0xed, 0xe1, 0x7b, 0xff, 0x2d, 0x66, 0x8c, 0x86, 0x77, 0x43, 0xeb,
-0xb6, 0xf6, 0x50, 0x66, 0xb0, 0x40, 0x24, 0x6a, 0xaf, 0x98, 0x21, 0x45, 0x30, 0x01, 0x59, 0xd0, 0xc3, 0xfc, 0x7b, 0xae,
-0x30, 0x18, 0xeb, 0x90, 0xfb, 0x17, 0xd3, 0xce, 0xb5
-};
-#endif
-
-// TODO: Move to subclass.
-Blob 
-PrivateKeyStorage::sign(const unsigned char *data, unsigned int dataLength, const string& keyName, DigestAlgorithm digestAlgorithm)
-{
-#if 1
-  if (digestAlgorithm != DIGEST_ALGORITHM_SHA256)
-    return Blob();
-
-  unsigned char digest[SHA256_DIGEST_LENGTH];
-  ndn_digestSha256(data, dataLength, digest);
-  // TODO: use RSA_size to get the proper size of the signature buffer.
-  unsigned char signatureBits[1000];
-  unsigned int signatureBitsLength;
-  // Use a temporary pointer since d2i updates it.
-  const unsigned char *derPointer = DEFAULT_PRIVATE_KEY_DER;
-  RSA *privateKey = d2i_RSAPrivateKey(NULL, &derPointer, sizeof(DEFAULT_PRIVATE_KEY_DER));
-  if (!privateKey)
-    throw std::runtime_error("Error decoding private key in d2i_RSAPrivateKey");
-  int success = RSA_sign(NID_sha256, digest, sizeof(digest), signatureBits, &signatureBitsLength, privateKey);
-  // Free the private key before checking for success.
-  RSA_free(privateKey);
-  if (!success)
-    throw std::runtime_error("Error in RSA_sign");
-  
-  return Blob(signatureBits, signatureBitsLength);
-#endif
-}
-
-}
diff --git a/ndn-cpp/security/identity/private-key-storage.hpp b/ndn-cpp/security/identity/private-key-storage.hpp
index 4bc91b9..3b71d37 100644
--- a/ndn-cpp/security/identity/private-key-storage.hpp
+++ b/ndn-cpp/security/identity/private-key-storage.hpp
@@ -10,36 +10,36 @@
 
 #include <string>
 #include "../../util/blob.hpp"
+#include "../certificate/public-key.hpp"
 #include "../security-common.hpp"
+#include "../../name.hpp"
 
 namespace ndn {
 
 class PrivateKeyStorage {
 public:
   /**
-   * The virtual destructor
+   * The virtual destructor.
    */    
   virtual 
-  ~PrivateKeyStorage();
+  ~PrivateKeyStorage() {}
 
-#if 0
   /**
-   * @brief generate a pair of asymmetric keys
-   * @param keyName the name of the key pair
-   * @param keyType the type of the key pair, e.g. RSA
-   * @param keySize the size of the key pair
+   * Generate a pair of asymmetric keys.
+   * @param keyName The name of the key pair.
+   * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
+   * @param keySize The size of the key pair.
    */
   virtual void 
-  generateKeyPair(const string & keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048) = 0;
+  generateKeyPair(const Name& keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048) = 0;
 
   /**
-   * @brief get the public key
-   * @param keyName the name of public key
-   * @return the public key
+   * Get the public key
+   * @param keyName The name of public key.
+   * @return The public key.
    */
-  virtual Ptr<Publickey> 
-  getPublickey(const string & keyName) = 0;
-#endif
+  virtual ptr_lib::shared_ptr<PublicKey> 
+  getPublicKey(const Name& keyName) = 0;
   
   /**
    * Fetch the private key for keyName and sign the data, returning a signature Blob.
@@ -47,50 +47,68 @@
    * @param dataLength The length of data.
    * @param keyName The name of the signing key.
    * @param digestAlgorithm the digest algorithm.
-   * @return The signature, or 0 if signing fails.
+   * @return The signature, or a null pointer if signing fails.
    */  
   virtual Blob 
-  sign(const unsigned char *data, unsigned int dataLength, const std::string& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256);
+  sign(const unsigned char *data, unsigned int dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) = 0;
     
-#if 0
+  Blob 
+  sign(const Blob& data, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256)
+  {
+    sign(data.buf(), data.size(), keyName, digestAlgorithm);
+  }
+  
   /**
-   * @brief decrypt data
-   * @param keyName the name of the decrypting key
-   * @param blob the blob to be decrypted
-   * @param sym if true symmetric encryption is used, otherwise asymmetric decryption is used.
-   * @return decrypted data
+   * Decrypt data.
+   * @param keyName The name of the decrypting key.
+   * @param data The byte to be decrypted.
+   * @param dataLength the length of data.
+   * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
+   * @return The decrypted data.
    */
-  virtual Ptr<Blob> 
-  decrypt(const string & keyName, const Blob & data, bool sym = false) = 0;
+  virtual Blob 
+  decrypt(const Name& keyName, const unsigned char* data, unsigned int dataLength, bool isSymmetric = false) = 0;
+
+  Blob 
+  decrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
+  {
+    decrypt(keyName, data.buf(), data.size(), isSymmetric);
+  }
 
   /**
-   * @brief encrypt data
-   * @param keyName the name of the encrypting key
-   * @param blob the blob to be encrypted
-   * @param sym if true symmetric encryption is used, otherwise asymmetric decryption is used.
-   * @return encrypted data
+   * Encrypt data.
+   * @param keyName The name of the encrypting key.
+   * @param data The byte to be encrypted.
+   * @param dataLength the length of data.
+   * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
+   * @return The encrypted data.
    */
-  virtual Ptr<Blob> 
-  encrypt(const string & keyName, const Blob & pData, bool sym = false) = 0;
+  virtual Blob
+  encrypt(const Name& keyName, const unsigned char* data, unsigned int dataLength, bool isSymmetric = false) = 0;
+
+  Blob
+  encrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
+  {
+    encrypt(keyName, data.buf(), data.size(), isSymmetric);
+  }
 
   /**
-   * @brief generate a symmetric key
-   * @param keyName the name of the key 
-   * @param keyType the type of the key, e.g. AES
-   * @param keySize the size of the key
+   * @brief Generate a symmetric key.
+   * @param keyName The name of the key.
+   * @param keyType The type of the key, e.g. KEY_TYPE_AES.
+   * @param keySize The size of the key.
    */
   virtual void 
-  generateKey(const string & keyName, KeyType keyType = KEY_TYPE_AES, int keySize = 256) = 0;
+  generateKey(const Name& keyName, KeyType keyType = KEY_TYPE_AES, int keySize = 256) = 0;
 
   /**
-   * @brief check if a particular key exist
-   * @param keyName the name of the key
-   * @param keyClass the class of the key, e.g. public, private, or symmetric
-   * @return true if the key exists, otherwise false
+   * Check if a particular key exists.
+   * @param keyName The name of the key.
+   * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
+   * @return True if the key exists, otherwise false.
    */
   virtual bool
-  doesKeyExist(const string & keyName, KeyClass keyClass) = 0;  
-#endif
+  doesKeyExist(const Name& keyName, KeyClass keyClass) = 0;  
 };
 
 }