Decryption Tutorial
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:
- Create an API key from the XQ Dashboard.
- Copy and paste the API key in the required api-key field.
- Enter the locator token in the locatorToken field.
- Enter the authToken in the authorization field. Prefix the authToken with Bearer.
- Run the request below (or use Test Request on the matching endpoint in the API reference).
Parameters — /key/{locatorToken}
| Name | Type | Required | Description |
|---|---|---|---|
api-key | string | Yes | General API key |
authorization | string | Yes | authToken returned in /exchange response. Prefix the auth token with "Bearer" |
locatorToken | string | This token is the response received when storing the key packet on the server. Make sure to URI encode the locatorToken |
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.
| Name | Type | Required | Description |
|---|---|---|---|
encryptedMessage | string | Yes | The message you want to decrypt |
key | string | Yes | The 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]