# Building JavaScript Application - Part 2

# HexaEight Session Capabilities

# 1. Encrypt/Decrypt

# 2. Protect/Decipher

# 3. HTTP Client (Axios Instance)

Lets extend the previous authentication example to incorporate HexaEight Sessions additional capabilities.

# Encrypt/Decrypt

In order to encrypt information to any destination, we first need to determine if the destination is a User Or Machine. If the destination is a user, we need to have the destination Email address, however if the destination is a Machine, then we need to have a fully qualified Domain Resource Name, or a Generic Resource Name. Once we have this information, its trivial to encrypt information to the destination using HexaEight Sessions.

So assume, we want to encrypt information to destination [email protected], we can use the HexaEight Session instance to encrypt information to the destination like below:


If the message encryption is successful, we should get a encrypted response. This message can be sent to the destination user or resource using any protocol. Note that it NOT necessary for the destination to be registered on HexaEight Platform for the encryption to work.

session.EncryptTextMessage("[email protected]","Hello Support Team, How are you doing Today");

If the encryption is successful, you can see the encrypted message as shown below


Note: Encrypting the same information again yeilds a different encrypted output

In order to decrypt information, you can use the DecryptTextMessage function as shown below, it not necessary to pass any additional information for decryption.


In order to test the encrypt/decrypt feature, you can open two sessions of HexaEight Session Demo in seperate tabs and login using different email address and try out the encrypt and decrypt message feature.

When a message is decrypted, the decrypted message will look like below :

{"REQUEST":"DATAMESSAGE","SENDER":"[email protected]","RECEIVER":"[email protected]","STIME":"1681599261","RTIME":"1681599285","BODY":"DEFAULT!6936D8CB97E03B8C288A231BAF26CB9F8E8ED127B1652CEC9E9620FE3D97CD108BDCBBDB7F5B7F6E51A40703E9AB9E6A0171A7A74FE89BC1C82D0E5DA0A0A141 [rcSh8YYtRF0Th3O552t5rEv5zysDVnSsAmO9Tz0VeuBMe2jfxASuGV2LPLH0UWJsx04vctHrxMcJFeCxRPRwUufHKfdNiVkv0r2DeNzWjrRD3LZGJOT6CoYWgEeTiMfT] :Hello Admin, How are you?"}

There is a lot of information that is available, lets break it down


    "SENDER":"[email protected]",
    "RECEIVER":"[email protected]",
    "BODY":"DEFAULT!6936D8CB97E03B8C288A231BAF26CB9F8E8ED127B1652CEC9E9620FE3D97CD108BDCBBDB7F5B7F6E51A40703E9AB9E6A0171A7A74FE89BC1C82D0E5DA0A0A141 [rcSh8YYtRF0Th3O552t5rEv5zysDVnSsAmO9Tz0VeuBMe2jfxASuGV2LPLH0UWJsx04vctHrxMcJFeCxRPRwUufHKfdNiVkv0r2DeNzWjrRD3LZGJOT6CoYWgEeTiMfT] :Hello Admin, How are you?"


While the first three fields are self explanatory, the STIME, is the start time when the message was encrypted at source and RTIME shows when the message was decrypted in the destination.

The BODY field has multiple data information points, lets split it up for better explanation.

  1. The DEFAULT refers to the SCOPE/ROLE that the user is currently logged in,
  2. The next text following the ! is the CLIENTAPPLICATION HASH, which is nothing but the hash of "hexaeight.github.io", which indicates to us that the user has used the Demo Application to send the message,
  3. The subsequent text in the Square Braces is the PKCE code verifier, which can be used as double verification to verify the sender's identity
  4. The final text shows the decrypted text.

# Protect/Decipher - Saving Data to Local/Session Storage

Storing data in the browser's storage is not considered safe, however HexaEight Sessions provides a simple way to store the data locally by using the "Protect Message" feature provided by HexaEight Session API. This allows us to store information in the browser's local storage and retrieve it later using the "Decipher Message" function to unprotect the data.

The below function will Protect the message which can be then saved in local/session storage

session.ProtectMessage("Protect this secret message 1000");

In order to unprototect the message


This Protect and dechipher message can be very useful, when you want to retrieve the user data for an app and store it locally in the protected state, thus reducing the roundtrip to fetch older data from the server every time the user logs into the session. Instead only the latest data can be fetched from the Server on subsequent session logins.

Note: The user needs to use the same Generic Resource Identity Token, for the data to be accessible in subsequent sessions.

You can use the following URL https://hexaeight.github.io/hexaeight-session-demo/ to test Encryption/Decryption as well as Protection/Deciphering API provided by HexaEight Sessions