diff --git a/src/cpp/lib/BinHexConverter.cpp b/src/cpp/lib/BinHexConverter.cpp index 8f8f78535..cf6608d71 100644 --- a/src/cpp/lib/BinHexConverter.cpp +++ b/src/cpp/lib/BinHexConverter.cpp @@ -109,6 +109,24 @@ std::string convertBinToHex(const MemoryBin* data) sodium_bin2hex(*hex, hexSize, *data, binSize); + std::string hexString((const char*)*hex, hexSize); + mm->releaseMemory(hex); + return hexString; +} + +std::string convertPubkeyToHex(const unsigned char* pubkey) +{ + auto mm = MemoryManager::getInstance(); + size_t hexSize = crypto_sign_PUBLICKEYBYTES * 2 + 1; + size_t binSize = crypto_sign_PUBLICKEYBYTES; + + MemoryBin* hex = mm->getFreeMemory(hexSize); + memset(*hex, 0, hexSize); + + size_t resultBinSize = 0; + + sodium_bin2hex(*hex, hexSize, pubkey, binSize); + std::string hexString((const char*)*hex, hexSize); mm->releaseMemory(hex); return hexString; diff --git a/src/cpp/lib/BinHexConverter.h b/src/cpp/lib/BinHexConverter.h index 563f73ea6..7645f16d7 100644 --- a/src/cpp/lib/BinHexConverter.h +++ b/src/cpp/lib/BinHexConverter.h @@ -9,6 +9,8 @@ MemoryBin* convertBase64ToBin(const std::string& base64String); std::string convertBinToBase64(const MemoryBin* data); std::string convertBinToHex(const MemoryBin* data); +//! \param pubkey pointer to array with crypto_sign_PUBLICKEYBYTES size +std::string convertPubkeyToHex(const unsigned char* pubkey);