In sign and defaultSign, added wireFormat argument.
diff --git a/ndn-cpp/key-chain.cpp b/ndn-cpp/key-chain.cpp
index 242617d..8bd18b5 100644
--- a/ndn-cpp/key-chain.cpp
+++ b/ndn-cpp/key-chain.cpp
@@ -92,29 +92,17 @@
  * @param data The Data object with the fields to digest.
  * @param digest A pointer to a buffer of size SHA256_DIGEST_LENGTH to receive the data.
  */
-static void digestDataFieldsSha256(const Data &data, unsigned char *digest)
+static void digestDataFieldsSha256(const Data &data, WireFormat &wireFormat, unsigned char *digest)
 {
-  // Imitate BinaryXmlWireFormat::encodeData.
-  struct ndn_NameComponent nameComponents[100];
-  struct ndn_NameComponent keyNameComponents[100];
-  struct ndn_Data dataStruct;
-  ndn_Data_init
-    (&dataStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]), 
-     keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
-  data.get(dataStruct);
-
-  BinaryXmlEncoder encoder;
   unsigned int signedFieldsBeginOffset, signedFieldsEndOffset;
-  ndn_Error error;
-  if ((error = ndn_encodeBinaryXmlData(&dataStruct, &signedFieldsBeginOffset, &signedFieldsEndOffset, &encoder)))
-    throw std::runtime_error(ndn_getErrorString(error));
+  ptr_lib::shared_ptr<vector<unsigned char> > encoding = wireFormat.encodeData(data, &signedFieldsBeginOffset, &signedFieldsEndOffset);
   
-  digestSha256(&encoder.getOutput()->front() + signedFieldsBeginOffset, signedFieldsEndOffset - signedFieldsBeginOffset, digest);
+  digestSha256(&encoding->front() + signedFieldsBeginOffset, signedFieldsEndOffset - signedFieldsBeginOffset, digest);
 }
 
 void KeyChain::sign
   (Data &data, const unsigned char *publicKeyDer, unsigned int publicKeyDerLength, 
-   const unsigned char *privateKeyDer, unsigned int privateKeyDerLength)
+   const unsigned char *privateKeyDer, unsigned int privateKeyDerLength, WireFormat &wireFormat)
 {
   // Set the public key.
   setSha256(publicKeyDer, publicKeyDerLength, data.getSignedInfo().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest());
@@ -125,7 +113,7 @@
 
   // Sign the fields.
   unsigned char dataFieldsDigest[SHA256_DIGEST_LENGTH];
-  digestDataFieldsSha256(data, dataFieldsDigest);
+  digestDataFieldsSha256(data, wireFormat, dataFieldsDigest);
   // TODO: use RSA_size to get the proper size of the signature buffer.
   unsigned char signature[1000];
   unsigned int signatureLength;
@@ -143,11 +131,17 @@
   data.getSignature().setSignature(signature, signatureLength);
 }
 
-void KeyChain::defaultSign(Data &data)
+void KeyChain::defaultSign(Data &data, WireFormat &wireFormat)
 {
   sign(data, DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER), DEFAULT_PRIVATE_KEY_DER, sizeof(DEFAULT_PRIVATE_KEY_DER));
 }
 
+void KeyChain::defaultSign(Data &data)
+{
+  sign(data, DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER), DEFAULT_PRIVATE_KEY_DER, sizeof(DEFAULT_PRIVATE_KEY_DER),
+       *WireFormat::getDefaultWireFormat());
+}
+
 bool KeyChain::selfVerifyData(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat)
 {
   // Decode the data packet and digest the data fields.
diff --git a/ndn-cpp/key-chain.hpp b/ndn-cpp/key-chain.hpp
index 6fa9c0a..cc15882 100644
--- a/ndn-cpp/key-chain.hpp
+++ b/ndn-cpp/key-chain.hpp
@@ -22,14 +22,22 @@
    * @param publicKeyDerLength The number of bytes in publicKeyDer.
    * @param privateKeyDer A pointer to a buffer with the DER-encoded private key.
    * @param privateKeyDerLength The number of bytes in privateKeyDer.
+   * @param wireFormat The WireFormat for calling encodeData.
    */
   static void sign
     (Data &data, const unsigned char *publicKeyDer, unsigned int publicKeyDerLength, 
-     const unsigned char *privateKeyDer, unsigned int privateKeyDerLength);
+     const unsigned char *privateKeyDer, unsigned int privateKeyDerLength, WireFormat &wireFormat);
 
   /**
    * Call sign with the default public and private keys.
    * @param data
+   * @param wireFormat The WireFormat for calling encodeData.
+   */
+  static void defaultSign(Data &data, WireFormat &wireFormat);
+
+  /**
+   * Call sign with the default public and private keys.  For wireFormat, use WireFormat::getDefaultWireFormat().
+   * @param data
    */
   static void defaultSign(Data &data);