Data Encryption

🔐 REL-ID SDK API Documentation: EncryptDataPacket & DecryptDataPacket

📘 Overview

The EncryptDataPacket and DecryptDataPacket APIs in the REL-ID SDK are used to securely encrypt and decrypt string data using defined cipher algorithms, salts, and privacy scopes. These APIs support secure data handling in various security contexts like session-based, user-based, device-based, or application-based.

🎯 Purpose

  • EncryptDataPacket: Securely transforms plain text into encrypted form using REL-ID cryptographic services.
  • DecryptDataPacket: Restores encrypted text back to readable plain text using the same parameters.

These functions are essential in scenarios where sensitive data such as user credentials or tokens need to be stored or transmitted securely.


🧩 SDK Context from REL-ID Integration Guide

🔒 Privacy Scope

Defines the key generation context for encryption/decryption. The supported values are:

ValueScopeDescription
1SESSIONKeys valid for the active session only (short-lived)
2DEVICEKeys tied to the device hardware identity
3USERKeys associated with the currently logged-in user
4AGENTKeys linked to the application agent context
🧠

Note: The session scope key is regenerated upon re-authentication and is different for USER and APP sessions.



🔁 Workflow Overview

  1. Retrieve cipherSpec and cipherSalt using "getDefaultCipherSpec() and getDefaultCipherSalt()
  2. Call encryptDataPacket() to convert plain text into encrypted format
  3. Store/transmit the encrypted data securely
  4. Use decryptDataPacket() with the same parameters to retrieve the original plain text

🔐 EncryptDataPacket API

📥 Parameters

FieldTypeDescription
privacyScopeintEncryption scope (see Privacy Scope)
cipherSpecstringCipher format string
cipherSaltstringExtra entropy value (recommended: app package name), in bytes
plainTextstringData to encrypt, in bytes

🔒 Privacy Scope

Defines the key generation context for encryption/decryption. The supported values are:

ValueScopeDescription
1SESSIONKeys valid for the active session only (short-lived)
2DEVICEKeys tied to the device hardware identity
3USERKeys associated with the currently logged-in user
4AGENTKeys linked to the application agent context
🧠

Note: The session scope key is regenerated upon re-authentication and is different for USER and APP sessions.


🧪 CipherSpec & CipherSalt

  • cipherSpec defines the encryption algorithm, key size, cipher mode, padding, and hash function.
    Format: ALGO/KEYSIZE/MODE/PADDING:HASH Example: AES/256/CFB/NoPadding:SHA-256
    • Supported encryption algorithms: AES
    • Supported modes: ECB, CBC, CFB, OFB
    • Padding: NoPadding, PKCS7Padding, ISO10126Padding
    • Hash: SHA-256, MD4, etc.
    • Recommended: AES/256/CFB/NoPadding:SHA-256
    • Stream ciphers are not supported for data-at-rest scenarios.

🧪 CipherSalt

cipherSalt: An additional entropy string added to the encryption. It ensures uniqueness of the cipher. Recommended value is the app’s package name (e.g., com.uniken.mybank).


💻 Code Snippets

React Native
RdnaClient.encryptDataPacket(privacyScope, cipherSpec, cipherSalt, plainText, (response) => {
  const encryptedData = response.response;
});
Flutter
final encrypted = await rdnaClient.encryptDataPacket(privacyScope, cipherSpec, cipherSalt, plainText);
Cordova
com.uniken.rdnaplugin.RdnaClient.encryptDataPacket(successCallback, errorCallback, [privacyScope, cipherSpec, cipherSalt, plainText]);
Native iOS
(RDNAError *)encryptDataPacket:(int)privacyScope
               CipherSpec:(NSString *)cipherSpec
               CipherSalt:(NSString *)cipherSalt
                     From:(NSData *)plainText
                     Into:(NSMutableData **)cipherText;
Native Android
RDNAStatus<byte[]> status = rdnaClient.encryptDataPacket(privacyScope, cipherSpec, cipherSalt.getBytes(), plainText.getBytes());
byte[] encrypted = status.getResponse();

🔓 DecryptDataPacket API

📥 Parameters

FieldTypeDescription
privacyScopeintDecryption scope used during encryption
cipherSpecstringSame cipher used in encryption
cipherSaltstringSame salt used in encryption, in bytes
cipherTextstringEncrypted data

💻 Code Snippets

React Native
RdnaClient.decryptDataPacket(privacyScope, cipherSpec, cipherSalt, cipherText, (response) => {
  const plainText = response.response;
});
Flutter
final plainText = await rdnaClient.decryptDataPacket(privacyScope, cipherSpec, cipherSalt, cipherText);
Cordova
com.uniken.rdnaplugin.RdnaClient.decryptDataPacket(successCallback, errorCallback, [privacyScope, cipherSpec, cipherSalt, cipherText]);
Native iOS
(RDNAError *)decryptDataPacket:(int)privacyScope
               CipherSpec:(NSString *)cipherSpec
               CipherSalt:(NSString *)cipherSalt
                     From:(NSData *)cipherText
                     Into:(NSMutableData **)plainText;
Native Android
RDNAStatus<byte[]> status = rdnaClient.decryptDataPacket(privacyScope, cipherSpec, cipherSalt.getBytes(), cipherText.getBytes());
byte[] plainText = status.getResponse();

⚠️ Error Codes - TBD


🧠 Developer Tips

  • Always match privacyScope, cipherSpec, and cipherSalt between encryption and decryption.
  • Use getDefaultCipherSpec() and getDefaultCipherSalt() to avoid hardcoding cipher formats.
  • Session-scope keys are ephemeral. Do not reuse across sessions.
  • Avoid using stream ciphers for persistent data encryption.