HEX
Server: Apache
System: Linux hp3-wp-1011494.hostingp3.local 3.10.0-1160.139.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Nov 3 13:30:41 UTC 2025 x86_64
User: csh2729955 (2121743)
PHP: 7.4.33
Disabled: shell_exec,exec,system,popen,set_time_limit
Upload Files
File: /home/storage/162/3480162/user/htdocs/wp-content/plugins/enlighter/modules/skltn/Hash.php
<?php
// ---------------------------------------------------------------------------------------------------------------
// -- WP-SKELETON AUTO GENERATED FILE - DO NOT EDIT !!!
// --
// -- Copyright (c) 2016-2020 Andi Dittrich
// -- https://github.com/AndiDittrich/WP-Skeleton
// --
// ---------------------------------------------------------------------------------------------------------------
// --
// -- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// -- If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// --
// ---------------------------------------------------------------------------------------------------------------

// Hash Wrapper/Utility

namespace Enlighter\skltn;

class Hash{

    const DEFAULT_ALGORITHM = 'sha256';

    // generate a length-limited hash with DEFAULT_ALGORITHM in hex format
    public static function hex($data, $length=null){
        // non string data ? use json encoding
        if (!is_string($data)){
            $data = json_encode($data);
        }

        // calculate hash
        $hash = hash(self::DEFAULT_ALGORITHM, $data);

        // limit length ?
        if ($length !== null){
            $hash = substr($hash, 0, $length);
        }

        return $hash;
    }

    // generate a length-limited hash with DEFAULT_ALGORITHM in base64 format
    public static function base64($data, $length=null){
        // non string data ? use json encoding
        if (!is_string($data)){
            $data = json_encode($data);
        }

        // calculate hash and use base64 encoding
        $hash = base64_encode(hash(self::DEFAULT_ALGORITHM, $data, true));

        // limit length ?
        if ($length !== null){
            $hash = substr($hash, 0, $length);
        }

        return $hash;
    }

    // generate a length-limited hash with DEFAULT_ALGORITHM in base64 format with url safe characters
    public static function filename($data, $length=null){
        // base64
        $hash = self::base64($data, $length);

        // url safe
        $hash = str_replace(array('+', '/', '='), array('-', '_', ''), $hash);

        return $hash;
    }
}