public static function generateKey($txt, $length = null)
    {

        date_default_timezone_set('UTC');

        $possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";

        $maxlength = (empty($length) || (int)$length > strlen($possible)) ? strlen($possible) : (int)$length;
        $random = "";

        $i = 0;

        while ($i < ($maxlength / 5)) {
            // pick a random character from the possible ones
            $char = substr($possible, mt_rand(0, $maxlength - 1), 1);
            if (!strstr($random, $char)) {
                $random .= $char;
                $i++;
            }
        }

        $salt = time() . $random;
        $rand = mt_rand();
        $key = md5($rand . $txt . $salt);

        return $key;
    }
public static function generateKey($txt, $length = null)
    {

        date_default_timezone_set('UTC');

        $possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";

        $maxlength = (empty($length) || (int)$length > strlen($possible)) ? strlen($possible) : (int)$length;
        $random = "";

        $i = 0;

        while ($i < ($maxlength / 5)) {
            // pick a random character from the possible ones
            $char = substr($possible, mt_rand(0, $maxlength - 1), 1);
            if (!strstr($random, $char)) {
                $random .= $char;
                $i++;
            }
        }

        $salt = time() . $random;
        $rand = mt_rand();
        $key = md5($rand . $txt . $salt);

        return $key;
    }
public static function generateKey ( $ txt , $ length = null ) { date_default_timezone_set ( 'UTC' ) ; $ possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ" ; $ maxlength = ( empty ( $ length ) || ( int ) $ length > strlen ( $ possible ) ) ? strlen ( $ possible ) : ( int ) $ length ; $ random = "" ; $ i = 0 ; while ( $ i < ( $ maxlength / 5 ) ) { // pick a random character from the possible ones $ char = substr ( $ possible , mt_rand ( 0 , $ maxlength - 1 ) , 1 ) ; if ( ! strstr ( $ random , $ char ) ) { $ random .= $ char ; $ i ++ ; } } $ salt = time ( ) . $ random ; $ rand = mt_rand ( ) ; $ key = md5 ( $ rand . $ txt . $ salt ) ; return $ key ; }
Generates a random encryption key

@param string $txt
@return string
Generates a random encryption key