Skip to content

Encrypted communication

It's recommended to enable encrypted communication with your Tap device if you are not using secure protocol.

import { Tap }  from '@iotize/device-client.js/device';

let tap: Tap; // ... your device

try{
    await tap.encryption(
        true, // enabled
        false // ask to reset session key (false by default)
    );

    // Now all requests will be encrypted
    let response = await tap.service.device.getSerialNumber();

    // Once you are done, you can stop encryption
    await tap.encryption(false);
}
catch (err){
    // Encryption cannot be enabled if there is an error.
    // This may happen for example if your device is not connected...
}

import com.iotize.android.device.device.impl.IoTizeDevice;

// ...
IoTizeDevice device = ...; // your device

// Enable encryption (it may throw an error)
device.enableEncryption(true);

// Now all requests will be encrypted
// Use your device object as usual
String serialNumber = device.service.device.getSerialNumber().get();
// ...

// Once you are done, you can stop encryption
device.enableEncryption(false);
import TapDeviceClient

let device: IoTizeDevice = ...; // your connected device

do {
    // Enable
    try device.encryption(enabled: true)

    // Now all requests will be encrypted
    // Use your device object as usual
    try device.service.device.getSerialNumber().body()

    // Disable encryption
    try device.encryption(enabled: false)
}
catch let error {
    // handle error
}