ifDeviceCrypto

Implemented By

NameDescription
roDeviceCryptoEncrypts and decrypts data on a device using a key that is unique per app, device, or model.

Supported Methods

Encrypt (input as roByteArray, String as encType) as roByteArray

Description

Encrypts data on a device that is unique per device, app, or model.

Parameters

NameTypeDescription
inputroByteArrayThe data to be encrypted.
encTypeStringThe encryption key type, which is a string that may be set to "channel", "device", or "model":
encTypeDescription
deviceEncrypt data with a device unique key. This can be used to implement a secure storage-like algorithm.
channelEncrypt data with an app unique key This enables you to provision credentials, API tokens, or other data from the cloud to devices securely. Apps signed with same signing key will share the encryption key.
modelEncrypt app with a model unique key This is similar to the "channel" encryption type, but with the scope limited to a specific model.

Return Value

An roByteArray containing the encrypted data.

Decrypt (EncryptedData as roByteArray, String as encType) as roByteArray

Description

Decrypts data stored on a device that was previously encoded with the Encrypt() method.

Parameters

NameTypeDescription
EncryptedDataroByteArrayThe previously encoded data to be decrypted.
encTypeStringThe encryption key type, which is a string that may be set to "channel", "device", or "model" (see table below for details).

Return Value

An roByteArray containing the decrypted data.

Example

You can use the Encrypt() and Decrypt() methods to encrypt plaintext on a Roku device and then decode it, as demonstrated in the following example:

  ' store plaintext to be encrypted in an roByteArray
  ba = CreateObject("roByteArray")
  ba.FromAsciiString("plain text1")  

  ' create roDeviceCrypto object and specify a device key
  dc = CreateObject("roDeviceCrypto") encType = "device"

  ' encrypt plaintext using the device key and store the encoded data in an roByteArray
  encrypted = dc.Encrypt(ba, encType)

  ' decode the encrypted data and store the decrypted data in an roByteArray
  if encrypted <> invalid then
  	decrypted = dc.Decrypt(encrypted,encType)
  end if