public function generateSessionKey()
    {
        if (!isset($this->cryptParams['keysize'])) {
            throw new Exception('Unknown key size for type "' . $this->type . '".');
        }
        $keysize = $this->cryptParams['keysize'];

        $key = openssl_random_pseudo_bytes($keysize);

        if ($this->type === self::TRIPLEDES_CBC) {
            /* Make sure that the generated key has the proper parity bits set.
             * Mcrypt doesn't care about the parity bits, but others may care.
            */
            for ($i = 0; $i < strlen($key); $i++) {
                $byte = ord($key[$i]) & 0xfe;
                $parity = 1;
                for ($j = 1; $j < 8; $j++) {
                    $parity ^= ($byte >> $j) & 1;
                }
                $byte |= $parity;
                $key[$i] = chr($byte);
            }
        }

        $this->key = $key;
        return $key;
    }
public function generateSessionKey()
    {
        if (!isset($this->cryptParams['keysize'])) {
            throw new Exception('Unknown key size for type "' . $this->type . '".');
        }
        $keysize = $this->cryptParams['keysize'];

        $key = openssl_random_pseudo_bytes($keysize);

        if ($this->type === self::TRIPLEDES_CBC) {
            /* Make sure that the generated key has the proper parity bits set.
             * Mcrypt doesn't care about the parity bits, but others may care.
            */
            for ($i = 0; $i < strlen($key); $i++) {
                $byte = ord($key[$i]) & 0xfe;
                $parity = 1;
                for ($j = 1; $j < 8; $j++) {
                    $parity ^= ($byte >> $j) & 1;
                }
                $byte |= $parity;
                $key[$i] = chr($byte);
            }
        }

        $this->key = $key;
        return $key;
    }
public function generateSessionKey ( ) { if ( ! isset ( $ this -> cryptParams [ 'keysize' ] ) ) { throw new Exception ( 'Unknown key size for type "' . $ this -> type . '".' ) ; } $ keysize = $ this -> cryptParams [ 'keysize' ] ; $ key = openssl_random_pseudo_bytes ( $ keysize ) ; if ( $ this -> type === self :: TRIPLEDES_CBC ) { /* Make sure that the generated key has the proper parity bits set.
             * Mcrypt doesn't care about the parity bits, but others may care.
            */ for ( $ i = 0 ; $ i < strlen ( $ key ) ; $ i ++ ) { $ byte = ord ( $ key [ $ i ] ) & 0xfe ; $ parity = 1 ; for ( $ j = 1 ; $ j < 8 ; $ j ++ ) { $ parity ^= ( $ byte >> $ j ) & 1 ; } $ byte |= $ parity ; $ key [ $ i ] = chr ( $ byte ) ; } } $ this -> key = $ key ; return $ key ; }
Generates a session key using the openssl-extension.
In case of using DES3-CBC the key is checked for a proper parity bits set.
@return string
@throws Exception
Generates a session key using the openssl - extension . In case of using DES3 - CBC the key is checked for a proper parity bits set .