diff --git a/include/opendht/default_types.h b/include/opendht/default_types.h
index f6469d8dbd2993b3612f1a86ea8c8dc19bef397c..73547447f59a731dfb58c7cb9a0fda2efbba5c3e 100644
--- a/include/opendht/default_types.h
+++ b/include/opendht/default_types.h
@@ -77,7 +77,7 @@ public:
         return [](const Value& v){ return v.isSigned(); };
     }
 
-    Sp<const crypto::PublicKey> owner;
+    Sp<crypto::PublicKey> owner;
     dht::InfoHash from;
 };
 
diff --git a/include/opendht/securedht.h b/include/opendht/securedht.h
index c944e568c60c38659ae99c6c419be6ad1537e01b..237dfb50058bf363f5d1188cd354319d7a6d7703 100644
--- a/include/opendht/securedht.h
+++ b/include/opendht/securedht.h
@@ -126,13 +126,13 @@ public:
     Value decrypt(const Value& v);
 
     void findCertificate(const InfoHash& node, const std::function<void(const Sp<crypto::Certificate>)>& cb);
-    void findPublicKey(const InfoHash& node, const std::function<void(const Sp<const crypto::PublicKey>)>& cb);
+    void findPublicKey(const InfoHash& node, const std::function<void(const Sp<crypto::PublicKey>)>& cb);
 
-    const Sp<crypto::Certificate> registerCertificate(const InfoHash& node, const Blob& cert);
+    Sp<crypto::Certificate> registerCertificate(const InfoHash& node, const Blob& cert);
     void registerCertificate(Sp<crypto::Certificate>& cert);
 
-    const Sp<crypto::Certificate> getCertificate(const InfoHash& node) const;
-    const Sp<const crypto::PublicKey> getPublicKey(const InfoHash& node) const;
+    Sp<crypto::Certificate> getCertificate(const InfoHash& node) const;
+    Sp<crypto::PublicKey> getPublicKey(const InfoHash& node) const;
 
     /**
      * Allows to set a custom callback called by the library to find a locally-stored certificate.
@@ -354,7 +354,7 @@ private:
 
     // our certificate cache
     std::map<InfoHash, Sp<crypto::Certificate>> nodesCertificates_ {};
-    std::map<InfoHash, Sp<const crypto::PublicKey>> nodesPubKeys_ {};
+    std::map<InfoHash, Sp<crypto::PublicKey>> nodesPubKeys_ {};
 
     std::atomic_bool forward_all_ {false};
     bool enableCache_ {false};
diff --git a/include/opendht/value.h b/include/opendht/value.h
index 70539bb867214c80ada249af62216ede75e56c18..a99363705b91a11192e0904ad2c3ce6b58e25ac9 100644
--- a/include/opendht/value.h
+++ b/include/opendht/value.h
@@ -356,7 +356,7 @@ struct OPENDHT_PUBLIC Value
     void sign(const crypto::PrivateKey& key) {
         if (isEncrypted())
             throw DhtException("Can't sign encrypted data.");
-        owner = std::make_shared<const crypto::PublicKey>(key.getPublicKey());
+        owner = std::make_shared<crypto::PublicKey>(key.getPublicKey());
         signature = key.sign(getToSign());
     }
 
@@ -368,8 +368,8 @@ struct OPENDHT_PUBLIC Value
         return isSigned() and owner->checkSignature(getToSign(), signature);
     }
 
-    std::shared_ptr<const crypto::PublicKey> getOwner() const {
-        return std::static_pointer_cast<const crypto::PublicKey>(owner);
+    std::shared_ptr<crypto::PublicKey> getOwner() const {
+        return std::static_pointer_cast<crypto::PublicKey>(owner);
     }
 
     /**
@@ -594,7 +594,7 @@ struct OPENDHT_PUBLIC Value
     /**
      * Public key of the signer.
      */
-    std::shared_ptr<const crypto::PublicKey> owner {};
+    std::shared_ptr<crypto::PublicKey> owner {};
 
     /**
      * Hash of the recipient (optional).
diff --git a/src/securedht.cpp b/src/securedht.cpp
index bf471d5d82a765983a747304cc17f12d969736e0..407c86b2b3bbf4e4d66897d3e023749c2d4f9f21 100644
--- a/src/securedht.cpp
+++ b/src/securedht.cpp
@@ -118,7 +118,7 @@ SecureDht::secureType(ValueType&& type)
     return type;
 }
 
-const Sp<crypto::Certificate>
+Sp<crypto::Certificate>
 SecureDht::getCertificate(const InfoHash& node) const
 {
     if (node == getId())
@@ -130,7 +130,7 @@ SecureDht::getCertificate(const InfoHash& node) const
         return it->second;
 }
 
-const Sp<const crypto::PublicKey>
+Sp<crypto::PublicKey>
 SecureDht::getPublicKey(const InfoHash& node) const
 {
     if (node == getId())
@@ -142,7 +142,7 @@ SecureDht::getPublicKey(const InfoHash& node) const
         return it->second;
 }
 
-const Sp<crypto::Certificate>
+Sp<crypto::Certificate>
 SecureDht::registerCertificate(const InfoHash& node, const Blob& data)
 {
     Sp<crypto::Certificate> crt;
@@ -220,7 +220,7 @@ SecureDht::findCertificate(const InfoHash& node, const std::function<void(const
 }
 
 void
-SecureDht::findPublicKey(const InfoHash& node, const std::function<void(const Sp<const crypto::PublicKey>)>& cb)
+SecureDht::findPublicKey(const InfoHash& node, const std::function<void(const Sp<crypto::PublicKey>)>& cb)
 {
     auto pk = getPublicKey(node);
     if (pk && *pk) {
@@ -405,7 +405,7 @@ SecureDht::putEncrypted(const InfoHash& hash, const InfoHash& to, Sp<Value> val,
             callback(false, {});
         return;
     }
-    findPublicKey(to, [=](const Sp<const crypto::PublicKey>& pk) {
+    findPublicKey(to, [this, hash, val = std::move(val), callback = std::move(callback), permanent](const Sp<crypto::PublicKey>& pk) {
         if(!pk || !*pk) {
             if (callback)
                 callback(false, {});
diff --git a/src/value.cpp b/src/value.cpp
index f6e2b1a947b419e65ac797c836fbd1d4fbf1a7b4..5ea34384af11807be444680af95da9aaa29e87b4 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -163,7 +163,7 @@ Value::msgpack_unpack_body(const msgpack::object& o)
                 throw msgpack::type_error();
             crypto::PublicKey new_owner;
             new_owner.msgpack_unpack(*rowner);
-            owner = std::make_shared<const crypto::PublicKey>(std::move(new_owner));
+            owner = std::make_shared<crypto::PublicKey>(std::move(new_owner));
             if (auto rrecipient = findMapValue(*rbody, VALUE_KEY_TO)) {
                 recipient = rrecipient->as<InfoHash>();
             }
@@ -193,7 +193,7 @@ Value::Value(const Json::Value& json)
     if (jowner.isString()) {
         auto ownerStr = jowner.asString();
         auto ownerBlob = std::vector<unsigned char>(ownerStr.begin(), ownerStr.end());
-        owner = std::make_shared<const crypto::PublicKey>(ownerBlob);
+        owner = std::make_shared<crypto::PublicKey>(ownerBlob);
     }
     const auto& jto = json[VALUE_KEY_TO];
     if (jto.isString())