Security::cipher PHP Method

cipher() public static method

public static cipher ( $text, $key )
    public static function cipher($text, $key)
    {
        if (empty($key)) {
            trigger_error('You cannot use an empty key for Security::cipher()', E_USER_WARNING);
            return null;
        }
        if (!defined('CIPHER_SEED')) {
            define('CIPHER_SEED', '76859309657453542496749683645');
        }
        srand(CIPHER_SEED);
        $output = '';
        for ($i = 0; $i < strlen($text); $i++) {
            for ($j = 0; $j < ord(substr($key, $i % strlen($key), 1)); $j++) {
                rand(0, 255);
            }
            $mask = rand(0, 255);
            $output .= chr(ord(substr($text, $i, 1)) ^ $mask);
        }
        return $output;
    }

Usage Example

Example #1
0
 function __encrypt($value)
 {
     if (is_array($value)) {
         $value = $this->__implode($value);
     }
     return "Q2FrZQ==." . base64_encode(Security::cipher($value, $this->Controller->Cookie->key));
 }
All Usage Examples Of Security::cipher