# User Payload

This section explains how will you generate user payload string that will be used in Config initialization. User payload generation is accomplished with the following 3 steps:

# Form Your User Data

The user payload must include the following fields in your data:

  "user_id": "string user id",
  "user_name": "string user name",
  "user_avatar_url": "string user avatar url",
  "user_followings": [
    "string user id 1",
    "string user id 2",
    "string user id 3"
  "user_creator_tags": [
    "string user creator tag 1",
    "string user creator tag 2",
    "string user creator tag 3"
  "user_consumer_tags": [
    "string user consumer tag 1",
    "string user consumer tag 2",
    "string user consumer tag 3"
  "expiration_time": integer timestamp in miliseconds


All of the fields should be presented in your data.

# Encrypt Your Data

User payload should be encrypted using AES Encryption in CBC mode with 256 Key size in bits. The payload is encrypted with initialization-vector and secret-key. Initialization-vector is 16 characters long whereas secret-key is 32 characters. When the Storyly Moments instance is created, random initialization-vector and secret-keys are generated along with the Storyly Moments token.

You can use sample encryption and encoding functions:

fun encrypt(message: ByteArray?): String {
      val key: SecretKeySpec? = SecretKeySpec("Storyly Moments Secret Key".toByteArray(), "AES")
      val iv: ByteArray? = "Storyly Moments Initialization Vector".toByteArray()
      val cipher = Cipher.getInstance(AES_MODE)
      val ivSpec = IvParameterSpec(iv)
      cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec)
      val cipherText = cipher.doFinal(message)
      val encryptedData = Base64.encodeToString(cipherText, Base64.NO_WRAP)
      return encryptedData

fun encode(userData: Map<String: Any>): JSONObject {
    return JSONObject(userPayload)

val sampleUserData = mapOf(
    "user_id" to "string user id",
    "user_name" to "string user name",
    "user_avatar_url" to "string user avatar url",
    "user_followings" to [ "string user id 1" ...],
    "expiration_time" to integer timestamp in miliseconds
val encodedData = encode(sampleUserData)
val encryptedData = encrypt(encodedData.toString().toByteArray())


The user payload is valid if it can be decrypted with the initialization vector and secret key of the Storyly Moments instance and if its expiration time is not expired.