Skip to main content

Data & Key Separation

The primary purpose of XQ's Developer APIs is to empower developers with tools to securely store user data while maintaining a strict separation of encryption keys from the data itself. These APIs enable developers to build platforms capable of managing both structured and unstructured confidential user data, ensuring encryption keys are stored independently to enhance security and reduce the risk of unauthorized access.

This separation allows developers to create robust, secure systems that comply with the highest standards for data protection and privacy, while still enabling the platform's users to retain full control over their data. Users benefit from knowing that their data is protected and that only authorized individuals or systems can access the encryption keys necessary to decrypt it. This approach fosters trust and ensures compliance with modern privacy regulations and best practices.

Confidential User Data Management​

Developers can integrate mechanisms into their applications that empower users to encrypt their data locally before storing it on the platform. The encryption keys can then be securely managed and stored separately through XQ, ensuring enhanced data security and user control.

This implementation also ensures that if a developer(s) platform gets compromised, the hacker won't have access to the decryption keys associated with the confidential data.

Client-Side Encryption​

Integrate XQ authentication seamlessly into your application's client-side authentication flow, enabling users to securely store encryption keys for their confidential data directly with XQ.

Step 1: Begin the login process.​

During the user login process, when a user authenticates with their email and password on your platform, you can invoke XQ's Authorize endpoint to initiate secure key management.

Parameters — /authorize

NameTypeRequiredDescription
api-keystringYesGeneral API key
userstringYesThe email address or phone number of the account to validate. The confirmation link or code will be sent to this address or number

POST
Headers
curl
curl -X POST 'https://subscription.xqmsg.net/v2/authorize' \
-H 'Content-Type: application/json' \
-H 'api-key: <API_KEY>' \
-d '{
"user": "test@example.com"
}'

Sent from your browser straight to subscription.xqmsg.net. Credentials stay in this tab and are cleared on reload; missing ones appear as <API_KEY> / <ACCESS_TOKEN> in the curl command.

Step 2: Prompt the user to enter the PIN.​

Your platform can prompt the user to enter the 2FA PIN sent to their registered email address. Once they have received their 2FA PIN they will input the value into your platform and you will call the codevalidation endpoint.

Parameters — /codevalidation

NameTypeRequiredDescription
tokenstringYesThe Pre-Auth token that is returned after an initial request for authorization.
pinintegerYesThe pin that was sent to the users email or phone number.

GET
Headers
Bearer
curl
curl -X GET 'https://subscription.xqmsg.net/v2/codevalidation?pin=123456' \
-H 'Authorization: Bearer <ACCESS_TOKEN>'

Sent from your browser straight to subscription.xqmsg.net. Credentials stay in this tab and are cleared on reload; missing ones appear as <API_KEY> / <ACCESS_TOKEN> in the curl command.

Step 3: Automatic Pre-Auth token exchange.​

If the users 2FA pin is valid, you can automatically exchange the pre-auth token on the client side application for the XQ Access Token.

Parameters — /exchange

NameTypeRequiredDescription
api-keystringYesGeneral API key
AuthorizationstringThis is a bearer token required to make most XQ API calls. To get one, a user must first utilize the authorize endpoint, upon which they get a pre-auth token. After they confirm their account utilizing the code-validation endpoint, they can then exchange the pre-auth token in return for an access token to a specific team.
bintegerThis is the specific Team ID you are using to exchange your pre-auth token for authorization. If no Team ID is specified, you will automatically be authorized into the Team ID with the lowest index that you have access to.

GET
Headers
Bearer
curl
curl -X GET 'https://subscription.xqmsg.net/v2/exchange?b=123' \
-H 'api-key: <API_KEY>' \
-H 'Authorization: Bearer <ACCESS_TOKEN>'

Sent from your browser straight to subscription.xqmsg.net. Credentials stay in this tab and are cleared on reload; missing ones appear as <API_KEY> / <ACCESS_TOKEN> in the curl command.

Step 4: Integrate client-side encryption​

Leverage XQ's Quantum Entropy in combination with client-side encryption libraries to robustly encrypt sensitive user data. This approach ensures that all data entered into your platform is securely encrypted, with encryption keys stored separately by XQ. Access to these keys can be restricted exclusively to the client, providing enhanced security and user control over their confidential information.

You can utilize XQ's Quantum Entropy generator to ensure strong encryption keys are generated.

Parameters — /

NameTypeRequiredDescription
ksstringYesThe number of entropy bits to fetch. Value will be returned as a base64-encoded hex string.

GET
curl
curl -X GET 'https://quantum.xqmsg.net/v2?ks=256'

Sent from your browser straight to quantum.xqmsg.net. Credentials stay in this tab and are cleared on reload.

The response is a base64-encoded hex string.

While the hex string returned in the response can be used as entropy, to retrieve the actual bits, the string should be decoded from base-64 and each hex character in the sequence converted to its 4-bit binary representation.

import CryptoJS from 'crypto-js';

// Example values
const data = "Highly Sensitive Data";
const key = "ff308a2a9e1671244dfe2e35ae0c8d1c9ddeec6b51128457ca29229a932d5574";

// Encrypt the message
const encrypted = CryptoJS.AES.encrypt(message, key).toString();

Step 5: Store the Encrypted Key Packet in XQ's Keystore​

Once the client has authorized themselves with XQ's backend, any data they encrypt using a secure encryption key can be stored directly in XQ's keystore. The key can be associated with a specific list of recipients, which may include only the user themselves. This ensures that the user retains exclusive access to their encrypted data, maintaining privacy and control.

Parameters — /packet/add

NameTypeRequiredDescription
api-keystringYesGeneral API key
authorizationstringYesauthToken returned in /exchange response. Prefix the auth token with "Bearer"
recipientsstringYesComma-delimited list of email addresses or phone numbers who are allowed to access the key.
expiresstringYesNumber of hours that this key will remain valid for. After this time, it will no longer be accessible.
keystringYesThe secret key that the user wants to protect.
typestringA value indicating the type of data that is being encrypted. Values are 1 = “file”, 2 = “msg”, 3 = “chat”, 4 = “form”, 5 = “data”
metaobjectAny additional meta information about the key.

POST
Headers
Bearer
curl
curl -X POST 'https://subscription.xqmsg.net/v2/packet/add' \
-H 'Content-Type: application/json' \
-H 'api-key: <API_KEY>' \
-H 'authorization: Bearer <ACCESS_TOKEN>' \
-d '{
"recipients": "test2@example.com",
"expires": "1",
"key": "xyz123",
"type": "msg",
"meta": {
"subject": "demo",
"title": "demo"
}
}'

Sent from your browser straight to subscription.xqmsg.net. Credentials stay in this tab and are cleared on reload; missing ones appear as <API_KEY> / <ACCESS_TOKEN> in the curl command.

Step 6: Store the Encrypted Data along with the Locator Token in your Backend.​

The encrypted data can then be securely stored in your backend along with the associated locator token generated in the previous step. In the event of a security breach or compromise, users' confidential data will remain safe, as every data item is uniquely encrypted using distinct encryption keys. These keys are stored separately with XQ, adding an additional layer of security and ensuring that even if the data is exposed, it cannot be decrypted without the associated key.

Since XQ never interacts with the data itself, even if XQ were compromised, a hacker would only gain access to the encryption keys—not the data, which remains secure and inaccessible.

Client-Side Decryption​

Users can retrieve encrypted data directly from your backend and use the corresponding locator token along with their XQ authorization token to request the encryption key from XQ's backend. The data is then decrypted on the client side, ensuring that the separation of data and keys is securely maintained.

Parameters — /key/{locatorToken}

NameTypeRequiredDescription
api-keystringYesGeneral API key
authorizationstringYesauthToken returned in /exchange response. Prefix the auth token with "Bearer"
locatorTokenstringThis token is the response received when storing the key packet on the server. Make sure to URI encode the locatorToken

GET
Headers
Bearer
curl
curl -X GET 'https://validation.xqmsg.net/v2/key/{locatorToken}' \
-H 'api-key: <API_KEY>' \
-H 'authorization: Bearer <ACCESS_TOKEN>'

Sent from your browser straight to validation.xqmsg.net. Credentials stay in this tab and are cleared on reload; missing ones appear as <API_KEY> / <ACCESS_TOKEN> in the curl command.


NameTypeRequiredDescription
encryptedMessagestringYesThe message you want to decrypt
keystringYesThe auth token received when creating a subscriber response

import CryptoJS from 'crypto-js';

const decrypted = CryptoJS.AES.decrypt(encryptedMessage, key).toString(CryptoJS.enc.Utf8);