diff --git a/ndn-cpp/fields/key-locator.cc b/ndn-cpp/fields/key-locator.cc
new file mode 100644
index 0000000..84fd60c
--- /dev/null
+++ b/ndn-cpp/fields/key-locator.cc
@@ -0,0 +1,200 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "key-locator.h"
+#include "ndn-cpp/error.h"
+
+namespace ndn {
+
+KeyLocator::KeyLocator ()
+  : m_type (NOTSET)
+  , m_data (0)
+{
+}
+
+KeyLocator::KeyLocator (const KeyLocator &keyLocator)
+  : m_type (keyLocator.getType ())
+  , m_data (0)
+{
+  switch (m_type)
+    {
+    case NOTSET:
+      break;
+    case KEY:
+      m_data = new Blob (keyLocator.getKey ());
+      break;
+    case CERTIFICATE:
+      m_data = new Blob (keyLocator.getCertificate ());
+      break;
+    case KEYNAME:
+      m_data = new Name (keyLocator.getKeyName ());
+      break;
+    }
+}
+
+KeyLocator::~KeyLocator ()
+{
+  deleteData ();
+}
+
+KeyLocator &
+KeyLocator::operator = (const KeyLocator &keyLocator)
+{
+  if (this == &keyLocator)
+    return *this;
+
+  deleteData ();
+  m_type = keyLocator.getType ();
+  
+  switch (m_type)
+    {
+    case NOTSET:
+      break;
+    case KEY:
+      m_data = new Blob (keyLocator.getKey ());
+      break;
+    case CERTIFICATE:
+      m_data = new Blob (keyLocator.getCertificate ());
+      break;
+    case KEYNAME:
+      m_data = new Name (keyLocator.getKeyName ());
+      break;
+    }
+
+  return *this;
+}
+
+void
+KeyLocator::deleteData ()
+{
+  switch (m_type)
+    {
+    case NOTSET: // nothing to clean up
+      break;
+    case KEY:
+      delete reinterpret_cast<Blob*> (m_data);
+      break;
+    case CERTIFICATE:
+      delete reinterpret_cast<Blob*> (m_data);
+      break;
+    case KEYNAME:
+      delete reinterpret_cast<Name*> (m_data);
+      break;
+    }
+}
+
+void
+KeyLocator::setType (KeyLocator::Type type)
+{
+  if (m_type == type)
+    return;
+
+  deleteData ();
+  m_type = type;
+  
+  switch (m_type)
+    {
+    case NOTSET:
+      m_data = 0;
+    case KEY:
+      m_data = new Blob;
+      break;
+    case CERTIFICATE:
+      m_data = new Blob;
+      break;
+    case KEYNAME:
+      m_data = new Name;
+      break;
+    }
+}
+
+const Blob &
+KeyLocator::getKey () const
+{
+  if (m_type != KEY)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("getKey called, but KeyLocator is not of type KeyLocator::KEY"));
+  return *reinterpret_cast<const Blob*> (m_data);
+}
+
+Blob &
+KeyLocator::getKey ()
+{
+  if (m_type != KEY)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("getKey called, but KeyLocator is not of type KeyLocator::KEY"));
+  return *reinterpret_cast<Blob*> (m_data);
+}
+
+void
+KeyLocator::setKey (const Blob &key)
+{
+  if (m_type != KEY)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("setKey called, but KeyLocator is not of type KeyLocator::KEY"));
+  *reinterpret_cast<Blob*> (m_data) = key;
+}
+
+const Blob &
+KeyLocator::getCertificate () const
+{
+  if (m_type != CERTIFICATE)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("getCertificate called, but KeyLocator is not of type KeyLocator::CERTIFICATE"));
+  return *reinterpret_cast<const Blob*> (m_data);
+}
+
+Blob &
+KeyLocator::getCertificate ()
+{
+  if (m_type != CERTIFICATE)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("getCertificate called, but KeyLocator is not of type KeyLocator::CERTIFICATE"));
+  return *reinterpret_cast<Blob*> (m_data);
+}
+
+void
+KeyLocator::setCertificate (const Blob &certificate)
+{
+  if (m_type != CERTIFICATE)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("setCertificate called, but KeyLocator is not of type KeyLocator::CERTIFICATE"));
+  *reinterpret_cast<Blob*> (m_data) = certificate;
+}
+
+const Name &
+KeyLocator::getKeyName () const
+{
+  if (m_type != KEYNAME)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("getKeyName called, but KeyLocator is not of type KeyLocator::KEYNAME"));
+  return *reinterpret_cast<const Name*> (m_data);
+}
+
+Name &
+KeyLocator::getKeyName ()
+{
+  if (m_type != KEYNAME)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("getKeyName called, but KeyLocator is not of type KeyLocator::KEYNAME"));
+  return *reinterpret_cast<Name*> (m_data);
+}
+
+
+void
+KeyLocator::setKeyName (const Name &name)
+{
+  if (m_type != KEYNAME)
+    BOOST_THROW_EXCEPTION (error::KeyLocator ()
+                           << error::msg ("setKeyName called, but KeyLocator is not of type KeyLocator::KEYNAME"));
+  *reinterpret_cast<Name*> (m_data) = name;
+}
+
+}
