finds.dev← search

// the find

markrad/IoTSASTokenGenerate

★ 8 · C · MIT · updated Jun 2020

C and C++ programs that demonstrates how to generate a SAS Token from a device connection string in order to connect a device to an Azure IoT hub without using the Microsoft SDK.

Three variants of Azure IoT Hub SAS token generation in C/C++ — one C++, one pure C, one no-malloc for constrained devices. Fills a real gap: if you're running a device that can't or won't use the Microsoft SDK, you need to generate this token yourself, and the algorithm is not obvious.

The no-malloc variant is the genuinely useful piece — rolling your own heap manager to avoid fragmentation on bare-metal targets is the kind of thing you actually need on an ESP8266 or similar. Bundling URL encoding and Base64 encode/decode inline keeps dependencies at zero, which matters on constrained hardware. Three implementations covering different C/C++ constraints gives you something to port from rather than starting from scratch. The connection string parsing approach mirrors what the SDK does internally, so the token format is correct.

The author's own README warns it leaks memory and skips error checking — that's a significant caveat for production use. No updates since 2020 and zero forks means this has seen no community review or fixes; the SHA-256 implementation is homebrew and unaudited. Project files are Visual Studio .vcxproj only, with no CMake or Makefile, so getting this onto a non-Windows toolchain requires manual work. Token expiry handling is not included — the sample generates a token but you're on your own for refresh logic, which is the harder part for long-running devices.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →