<?php

if(!function_exists('account_secure_me')){
    function account_secure_me($chaine, $unsecured = true){
        $output = false;
        $encrypt_method = "AES-256-CBC";
        $secret_key = 'hhfbszfcdvadwreas452hdhwreas452dtdfd';
        $secret_iv = 'hhfbszfcdvadwreas452hdhwreas452dtdfd';

        // hash
        $key = hash('sha256', $secret_key);
        // iv - encrypt method AES-256-CBC expects 16 bytes
        $iv = substr(hash('sha256', $secret_iv), 0, 16);
        // CRYPTER
        if ($unsecured) { // if true crypt
            $output = openssl_encrypt($chaine, $encrypt_method, $key, 0, $iv);
            $output = base64_encode($output);
        } else {        // else decrypt
            $output = openssl_decrypt(base64_decode($chaine), $encrypt_method, $key, 0, $iv);
        }
        return  $output;
    }
}

if(!function_exists('client_secure_me')){
    function client_secure_me($chaine, $unsecured = true){
        $output = false;
        $encrypt_method = "AES-256-CBC";
        $secret_key = 'hhfsyhrtgfegshwreas452dtf@GGS';
        $secret_iv = 'hhfsyhrtgfegshwreas452dtf@GGS';

        // hash
        $key = hash('sha256', $secret_key);
        // iv - encrypt method AES-256-CBC expects 16 bytes
        $iv = substr(hash('sha256', $secret_iv), 0, 16);
        // CRYPTER
        if ($unsecured) { // if true crypt
            $output = openssl_encrypt($chaine, $encrypt_method, $key, 0, $iv);
            $output = base64_encode($output);
        } else {        // else decrypt
            $output = openssl_decrypt(base64_decode($chaine), $encrypt_method, $key, 0, $iv);
        }
        return  $output;
    }
}


