I am using the below script to generate SAS_Token (refered: https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token) using URI, Device_ID & SAS_KEY in Linux(ARM) device. Further to this using curl API's from libcurl to POST to Azure IoT blob to create a file to write. But I am getting an error.

I am curious to know if this is a problem with system time that is getting generated or it is due to some problem with openssl sha256, for which it's generating an invalid token out of SAS_KEY, or does it require credentials like Username and Password for IoT hub when we are using curl to POST?

Kindly Help



ENCODED_URI=$(echo -n $EVENTHUB_URI | jq -s -R -r @uri)
TTL=$(date +%s)
UTF8_SIGNATURE=$(printf "%s\n%s" $ENCODED_URI $TTL | iconv -t utf8)

HASH=$(echo -n "$UTF8_SIGNATURE" | openssl sha256 -hmac $SHARED_ACCESS_KEY -binary | base64)
ENCODED_HASH=$(echo -n $HASH | jq -s -R -r @uri)

echo -n "SharedAccessSignature sr=$ENCODED_URI&sig=$ENCODED_HASH&se=$TTL"

Error Message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.