Skip to content

Security/Encryption

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

With the default Tap configuration, secure communication will be automatically enabled when you login. However, you can manually enable/disable encryption with the API.

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
}

Initialization vectors

!!! note "NEW!" - Since firmware version: 1.86 - API version: @iotize/device-client.js >= 0.0.1-alpha.105

Initialization vectors (IV) are used in data encryption to make it more difficult for a hacker to find patterns and break a cipher.

You can define how often IV must be changed. Changing the IV requires a request to the Tap, so it will slow down a little communication speed. For example, if you choose to change IV every 2 requests, you will have an additional request every 2 requests. If you change it for every request, the API is optimized to encapsulate the IV change inside your request, therefore you will not have an additional request, however you will have a bigger request/response frame.

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

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

// IV will be changed for every requests
tap.setInitializationVectorRefreshPeriod(1);

// IV will be changed for every 100 requests
tap.setInitializationVectorRefreshPeriod(100);

// To disable just set period to 0 (default)
tap.setInitializationVectorRefreshPeriod(0);

// Force IV change
await tap.refreshEncryptionInitializationVector();