How to avoid Base64 encryption for telemetry data through Azure IoT SDK

Giovanni Genta 21 Reputation points
2020-10-26T22:04:47.537+00:00

Hello,

I'm currently using Azure IoT Hub SDK 1.2.10 for my IoT project. The telemetry data sent from my IoT device should not be encrypted (JSON format) but I've noticed that the SDK does a Base64 encryption before sending the telemetry data to the cloud. How can I configure the Azure SDK in order to avoid the Base64 encryption?

Thank you in advance for your help.

Best regards,

Giovanni

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,133 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
208 questions
0 comments No comments
{count} votes

Accepted answer
  1. Matthijs van der Veer 4,376 Reputation points MVP
    2020-10-27T07:30:00.053+00:00

    You have to specify the content type and content encoding on your event, otherwise, the SDK will do Base64 encoding by default. Your question doesn't specify what language you're using, but here's a C# sample:

    string dataBuffer = $"{{\"foo\": 42,\"bar\":{42},}}";
    
    using var eventMessage = new Message(Encoding.UTF8.GetBytes(dataBuffer))
    {
        ContentType = "application/json",
        ContentEncoding = Encoding.UTF8.ToString(),
    };
    
    await _deviceClient.SendEventAsync(eventMessage);
    

    There is a bit more context in this blog post.

    0 comments No comments

0 additional answers

Sort by: Most helpful