diff --git a/include/opendht/crypto.h b/include/opendht/crypto.h
index 8a1f86bdc5d86cc861c1159921ed7d265ad4f57f..ef87b415a57a1a4a85ef4c69333c88a8b12475e7 100644
--- a/include/opendht/crypto.h
+++ b/include/opendht/crypto.h
@@ -83,7 +83,9 @@ struct OPENDHT_PUBLIC PublicKey
     PublicKey& operator=(PublicKey&& o) noexcept;
 
     InfoHash getId() const;
+#if GNUTLS_VERSION_NUMBER >= 0x030401
     PkId getLongId() const;
+#endif
     bool checkSignature(const Blob& data, const Blob& signature) const;
     Blob encrypt(const Blob&) const;
 
@@ -362,7 +364,9 @@ struct OPENDHT_PUBLIC Certificate {
 
     /** Same as getPublicKey().getId() */
     InfoHash getId() const;
+#if GNUTLS_VERSION_NUMBER >= 0x030401
     PkId getLongId() const;
+#endif
 
     /** Read certificate Common Name (CN) */
     std::string getName() const;
diff --git a/include/opendht/securedht.h b/include/opendht/securedht.h
index acae729fd66dcb92b2c9c45a1d9683eacbdb3c9d..7e2004d9147da6b13c01a97b2e29e96f3a9a673a 100644
--- a/include/opendht/securedht.h
+++ b/include/opendht/securedht.h
@@ -51,10 +51,11 @@ public:
     InfoHash getId() const {
         return key_ ? key_->getPublicKey().getId() : InfoHash();
     }
+#if GNUTLS_VERSION_NUMBER >= 0x030401
     PkId getLongId() const {
         return key_ ? key_->getPublicKey().getLongId() : PkId();
     }
-
+#endif
     ValueType secureType(ValueType&& type);
 
     ValueType secureType(const ValueType& type) {
diff --git a/src/crypto.cpp b/src/crypto.cpp
index 7faf74c3b6ba6f391a58947e3edae5300d16e743..4b35b1eca3e3f2d6f92a7263c51ef513caf23974 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -532,6 +532,7 @@ PublicKey::getId() const
     return id;
 }
 
+#if GNUTLS_VERSION_NUMBER >= 0x030401
 PkId
 PublicKey::getLongId() const
 {
@@ -541,6 +542,7 @@ PublicKey::getLongId() const
         return {};
     return h;
 }
+#endif
 
 Certificate::Certificate(const Blob& certData) : cert(nullptr)
 {
@@ -646,6 +648,7 @@ Certificate::getId() const
     return id;
 }
 
+#if GNUTLS_VERSION_NUMBER >= 0x030401
 PkId
 Certificate::getLongId() const
 {
@@ -657,6 +660,7 @@ Certificate::getLongId() const
         throw CryptoException("Can't get certificate public key ID.");
     return id;
 }
+#endif
 
 static std::string
 getDN(gnutls_x509_crt_t cert, const char* oid, bool issuer = false)