Skip to main content

Integration Steps

Obtaining the Secret Key

Zamplia will provide you with a unique secret key for HMAC calculations. This key is confidential and should be treated with the same level of care as other sensitive credentials. Avoid sharing it publicly or storing it in unencrypted locations.

Choosing a Hash Function

Common and secure hash functions suitable for HMAC include SHA-256 (recommended) and SHA-1. This guide will demonstrate the implementation using SHA-256.

HMAC Calculation for Entry URLs

  • Message Preparation

    The message for entry URL HMAC calculation consists of the URL parameters, excluding the hash parameter (which will be added later).

  • HMAC Generation

    Example (crypto.js)
        const crypto = require('crypto');

    // Replace with your actual entry URL

    const entryUrl = 'https://res.zamplia.com/?vid=1719&isMap=1&sid=960826349&uid=Testtermpass555';

    const secretKey = 'your_secret_key'; // Replace with your actual secret key

    function generateHmac(url, key) {

    const hmac = crypto.createHmac('sha256', key);

    hmac.update(url);

    return hmac.digest('hex');

    }

    const hmacValue = generateHmac(entryUrl, secretKey);

    const finalUrl = entryUrl + '&hash=' + hmacValue;

    console.log('Final URL:', finalUrl);
  • Explanation

    • Import the crypto module.
    • Define the entryUrl variable.
    • Define the secretKey variable (replace with your actual secret key).
    • Create the generateHmac function that takes the URL and secret key as arguments.
    • Creates an HMAC object using crypto.createHmac with the SHA-256 algorithm.
    • Updates the HMAC object with the URL data using hmac.update.
    • Generates the HMAC digest in hexadecimal format using hmac.digest('hex').
    • Generate the HMAC value using the generateHmac function.
    • Append the HMAC value as a hash parameter to the original URL.
    • Print the final URL with the appended hash parameter.
  • Example with Entry URL

    Secret Key: 'your_secret_key'
    Entry URL: https://res.zamplia.com/?vid=1719&isMap=1&sid=960826349&uid=Testtermpass555
    Example (crypto.js)
        const crypto = require('crypto');

    let encryptionUrl = 'https://res.zamplia.com/?vid=1719&isMap=1&sid=960826349&uid=Testtermpass555';

    const encryptedKey = encryptionFunction(encryptionUrl);

    let finalUrl = encryptionUrl + '&hash=' + encryptedKey;

    function encryptionFunction(encryptionUrl) {

    const key = 'abcd1234';

    let encryptedValue = crypto.createHmac('sha256', key).update(encryptionUrl).digest('hex');

    encryptedValue = encryptedValue.split("+").join("-");

    encryptedValue = encryptedValue.split("/").join("_");

    return encryptedValue;

    }

    console.log(finalUrl);
    Output:
    https://res.zamplia.com/?vid=1719&isMap=1&sid=960826349&uid=Testtermpass555&hash=xxxxxxxxxxxxxxxxxxxxxxx