Documentation
NAV Navbar
PHP JavaScript
  • Hash API
  • Hash API

    Introduction

    The Kameleoon Hash API is used to ensure the integrity of the Kameleoon application file that you setup in your website. By using the Hash API, you make sure that our application file is not tampered with or changed by any other party and can be safely used inside your website.

    The integrity is achieved by retrieveing the hash code based on the content of the application file and then comparing to the hash code of the application file being integrated on your website. Both hash codes should be equal in all cases.

    The usage of the Kameleoon Hash API is quite straightforward and does not require a lot of modifications. This document will help you use our Hash API correctly and secure the application file from tampering.

    Description of the Hash API

    const apiURL = 'https://api.kameleoon.com/api/getHash';
    const siteCode ='uzguihqmj7';
    const hashType = 'SHA256';
    const hashURL = apiURL + '?siteCode=' + siteCode + '&hashType=' + hashType;
    
    const xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            // callback method to handle hashCode
            callback(xmlHttp.responseText.hashCode);
        }
    }
    xmlHttp.open("GET", hashURL, true);
    xmlHttp.send();
    
    <?php
    $API_URL = 'https://api.kameleoon.com/api/getHash';
    $SITE_CODE ='uzguihqmj7';
    $HASH_TYPE = 'SHA256';
    $HASH_URL = $API_URL . '?siteCode=' . $SITE_CODE . '&hashType=' . $HASH_TYPE;
    
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => $HASH_URL,
    ));
    
    $response = json_decode(curl_exec($curl));
    
    // Some method to compare the hash code
    checkHash(response.hashCode);
    
    curl_close($curl);
    

    To get started with the Hash API you will need to get your site code, which can be collected from the installation of your website on the Kameleoon platform. This code uniquely identifies your website, therefore please make sure to use the correct siteCode.

    To get the hashCode generated from the content of the original application file, you need to make a request to our Hash API:

    https://api.kameleoon.com/api/getHash?siteCode=uzguihqmj7&hashType=SHA256

    As can be seen from the example on the right, once you make a request to the API to get the hash code, you can compare it to the hash code computed on your side to make sure that the file wasn't tampered with in any way.

    Hash Types
    TypeDescription
    SHA256SHA-256 generates an almost-unique 256-bit (32-byte) signature for a text. This is the default hash algorithm.
    MD5The MD5 algorithm is a widely used hash function producing a 128-bit hash value.
    SHA1SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function which takes an input and produces a 160-bit (20-byte) hash value known as a message digest