Skip to main content

Decryption Tutorial

This tutorial is not a sandbox!

Any operations here behave as if you executed them from our own server.


Section 1 - Fetching your encryption key​

Before you can decrypt a message, you must retrieve the key that was used for encryption. Use the locator token that XQ provides when the key is uploaded.

Additionally, you must ensure the user that is fetching the token has the permissions to return this key. To verify the identity of the caller you need the authorization token of the subscriber.

See the Encryption tutorial for steps on generating these tokens. Store the authToken and locator token from this tutorial.

Use the following steps with the request below to fetch your encryption key:

  1. Create an API key from the XQ Dashboard.
  2. Copy and paste the API key in the required api-key field.
  3. Enter the locator token in the locatorToken field.
  4. Enter the authToken in the authorization field. Prefix the authToken with Bearer.
  5. Run the request below (or use Test Request on the matching endpoint in the API reference).

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.

A successful response will return the encryption key and verified the subscriber is valid and has access to the key.


Section 2 - Decrypting your message​

Use the encryption key to decrypt your message. How you decrypt your message will depend on the method you used to encrypt the data.

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);

openssl enc -d -k [key] -in [encrypted file] -out [decrypted file]