View file sys/inc/functions/shif.php

File size: 2.41Kb
<?php

function shif( $str )
{
    return md5(trim($str));
}

function cookie_encrypt($data, $id = 0)
{
    $key = SALT_COOKIE_USER; 

    $l = strlen($key);
    if ($l < 16)
        $key = str_repeat($key, ceil(16/$l));

    if ($m = strlen($data) % 8)
        $data .= str_repeat("\x00",  8 - $m);
    if (function_exists('openssl_encrypt'))
        $val = openssl_encrypt($data, 'BF-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);
    elseif (function_exists('mcrypt_encrypt'))
        $val = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_ECB);
    else 
        $val = $data; 

    return base64_encode($val);
}

function cookie_decrypt($data, $id = 0)
{
    $key = SALT_COOKIE_USER; 
    $data = base64_decode($data); 

    $l = strlen($key);
    if ($l < 16)
        $key = str_repeat($key, ceil(16/$l));

    if (function_exists('openssl_encrypt'))
        $val = openssl_decrypt($data, 'BF-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);
    elseif (function_exists('mcrypt_encrypt'))
        $val = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_ECB);
    else 
        $val = $data; 

    return $val;
}

/*
function cookie_encrypt( $str, $id = 0 )
{
    if ( defined('SALT_COOKIE_USER') && function_exists( 'mcrypt_module_open' ) ) {
        $td = mcrypt_module_open( 'rijndael-256', '', 'ofb', '' );
        $ks  = @mcrypt_enc_get_key_size( $td );
        $key = substr(md5($id . @$_SERVER['HTTP_USER_AGENT']), 0, $ks);
        @mcrypt_generic_init($td, $key, base64_decode(SALT_COOKIE_USER));
        $str = @mcrypt_generic( $td, $str );
        @mcrypt_generic_deinit( $td );
        @mcrypt_module_close( $td );
    }

    $str = base64_encode( $str );
    return $str;
}

function cookie_decrypt( $str, $id = 0 )
{
    $str = base64_decode( $str );
    
    if ( defined('SALT_COOKIE_USER') && function_exists( 'mcrypt_module_open' ) ) {
        $td = mcrypt_module_open( 'rijndael-256', '', 'ofb', '' );
        $ks  = @mcrypt_enc_get_key_size( $td );
        $key = substr( md5( $id . @$_SERVER['HTTP_USER_AGENT'] ), 0, $ks );
        @mcrypt_generic_init( $td, $key, base64_decode(SALT_COOKIE_USER) );
        $str = @mdecrypt_generic( $td, $str );
        @mcrypt_generic_deinit( $td );
        @mcrypt_module_close( $td );
    }
    return $str;
}
*/

function get_salt() 
{
    $hash = md5(SALT_COOKIE_USER);
    return $hash; 
}