Data: Change the cached wireEncoding_ to defaultWireEncoding_ so we only cache an encoding using the default wire format.  Change getWireEncoding() to getDefaultWireEncoding().
diff --git a/ndn-cpp/data.cpp b/ndn-cpp/data.cpp
index a31878e..c9f21fa 100644
--- a/ndn-cpp/data.cpp
+++ b/ndn-cpp/data.cpp
@@ -48,7 +48,7 @@
 }
 
 Data::Data(const Data& data)
-: name_(data.name_), metaInfo_(data.metaInfo_), content_(data.content_), wireEncoding_(data.wireEncoding_)
+: name_(data.name_), metaInfo_(data.metaInfo_), content_(data.content_), defaultWireEncoding_(data.defaultWireEncoding_)
 {
   if (data.signature_)
     signature_ = data.signature_->clone();
@@ -68,7 +68,7 @@
   name_ = data.name_;
   metaInfo_ = data.metaInfo_;
   content_ = data.content_;
-  wireEncoding_ = data.wireEncoding_;
+  defaultWireEncoding_ = data.defaultWireEncoding_;
 
   return *this;
 }
@@ -102,13 +102,17 @@
 }
 
 SignedBlob 
-Data::wireEncode(WireFormat& wireFormat) 
+Data::wireEncode(WireFormat& wireFormat) const
 {
   size_t signedPortionBeginOffset, signedPortionEndOffset;
   Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset);
+  SignedBlob wireEncoding = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset);
   
-  wireEncoding_ = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset);
-  return wireEncoding_;
+  if (&wireFormat == WireFormat::getDefaultWireFormat())
+    // This is the default wire encoding.
+    const_cast<Data*>(this)->defaultWireEncoding_ = wireEncoding;
+  
+  return wireEncoding;
 }
 
 void 
@@ -117,13 +121,18 @@
   size_t signedPortionBeginOffset, signedPortionEndOffset;
   wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset);
   
-  wireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset);
+  if (&wireFormat == WireFormat::getDefaultWireFormat())
+    // This is the default wire encoding.
+    defaultWireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset);
+  else
+    defaultWireEncoding_ = SignedBlob();
 }
 
 void 
 Data::onChanged()
 {
-  wireEncoding_ = SignedBlob();
+  // The values have changed, so the default wire encoding is invalidated.
+  defaultWireEncoding_ = SignedBlob();
 }
 
 }
diff --git a/ndn-cpp/security/key-chain.cpp b/ndn-cpp/security/key-chain.cpp
index 197fdfd..3fc3f77 100644
--- a/ndn-cpp/security/key-chain.cpp
+++ b/ndn-cpp/security/key-chain.cpp
@@ -77,11 +77,10 @@
   if (signature->getDigestAlgorithm().size() != 0)
     // TODO: Allow a non-default digest algorithm.
     throw UnrecognizedDigestAlgorithmException("Cannot verify a data packet with a non-default digest algorithm.");
-  if (!data.getWireEncoding())
-    // Don't expect this to happen
-    throw SecurityException("The Data wireEncoding is null.");
-  uint8_t signedPortionDigest[SHA256_DIGEST_LENGTH];
-  ndn_digestSha256(data.getWireEncoding().signedBuf(), data.getWireEncoding().signedSize(), signedPortionDigest);
+  if (!data.getDefaultWireEncoding())
+     data.wireEncode();
+ uint8_t signedPortionDigest[SHA256_DIGEST_LENGTH];
+  ndn_digestSha256(data.getDefaultWireEncoding().signedBuf(), data.getDefaultWireEncoding().signedSize(), signedPortionDigest);
   
   // Verify the signedPortionDigest.
   // Use a temporary pointer since d2i updates it.