Generate a rijndael 256 initialisation vector
@param resource $cypher Encryption Resource
@return string
427897
public static function _genRijndael256IV ($cypher = FALSE)
	{
		
		// If a module has not been passed
		
		if (!$cypher)
		{
			
			// Open the cypher
			
			$cypher		= mcrypt_module_open ('rijndael-256', '', 'ofb', '');
			
		}
		
		// Create the IV
		
		$iv	= mcrypt_create_iv (mcrypt_enc_get_iv_size ($cypher), MCRYPT_RAND);
		
		// Close Module
		
		mcrypt_module_close ($cypher);
		
		// Return IV
		
		return $iv;
		
	}
866278
public function onMatch(string $cypher): self
    {
        $clause = $this->clauses->last();

        if (
            !$clause instanceof Clause\MergeClause &&
            !$clause instanceof Clause\OnCreateClause
        ) {
            throw new NonMergeClause;
        }

        $query = new self;
        $query->clauses = $this->clauses->add(
            new Clause\OnMatchClause($cypher)
        );

        return $query;
    }
162326
public static function getPKCS1($key)
	{
		$prefix = '-----BEGIN RSA PUBLIC KEY-----';
		$postfix = '-----END RSA PUBLIC KEY-----';
		
		$key = str_replace($prefix, '', $key);
		$key = str_replace($postfix, '', $key);
		$key = str_replace("\n", '', $key);
		
		$lines = str_split($key, 65);
		$body = implode("\n", $lines);
		$result = $prefix . "\n";
		$result .= $body . "\n";
		$result .= $postfix;
		
		return $result;
	}
351392
public static function getCrypt($cryptKey = Crypt::DEFAULT_KEY, $mode = Crypt::MODE_ASCII): \Osf\Crypt\Crypt
    {
        return self::buildObject('\Osf\Crypt\Crypt', [$cryptKey, $mode]);
    }
377230
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;
    }
1207766
public static function encrypt(string $data, string $password): string
    {
        // Generate IV of appropriate size.
        $iv = self::generateIv();
        // Derive key from password
        $key = self::hash($iv, $password);
        // Encrypt the given data
        $cyphertext = openssl_encrypt($data, self::CIPHER, $key, OPENSSL_RAW_DATA, $iv);

        if ($cyphertext === false) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException('Encryption library: Encryption (symmetric) of content failed: ' . openssl_error_string());
            // @codeCoverageIgnoreEnd
        }
        // Checksum : Create a keyed hash for the encrypted data
        $checksum = self::hash($iv . $cyphertext, $key);
        // concat all the elements in the final encrypted string
        $encrypted = $iv . $checksum . $cyphertext;

        return $encrypted;
    }
1060342
public static function generateEncryptionKey(): EncryptionKey
    {
        // @codeCoverageIgnoreStart
        try {
            $secretKey = \random_bytes(\SODIUM_CRYPTO_STREAM_KEYBYTES);
        } catch (\Throwable $ex) {
            throw new CannotPerformOperation($ex->getMessage());
        }
        // @codeCoverageIgnoreEnd
        return new EncryptionKey(
            new HiddenString($secretKey)
        );
    }
422128
public function skip(string $cypher): self
    {
        $query = new self;
        $query->clauses = $this->clauses->add(
            new Clause\SkipClause($cypher)
        );

        return $query;
    }
866924
public function encrypt(string $data, string $password): string
    {
        $iv = $this->generateInitializationVector();
        $encryptedData = openssl_encrypt($data, self::CYPHER, $password, self::OPTIONS, $iv);
        if (false === $encryptedData) {
            $messages = [];
            while ($message = openssl_error_string()) {
                $messages[] = $message;
            }

            throw new CryptException('openssl_encrypt returned an error: '.implode(', ', $messages));
        }

        return $encryptedData.':'.bin2hex($iv);
    }
1280381
public static function crypt(string $str, string $key): string
    {
        $s = self::initializeState($key);
        $i = $j = 0;
        $res = '';
        $size = Str::strlen($str);
        for ($y = 0; $y < $size; $y++) {
            $i = ($i + 1) % 256;
            $j = ($j + $s[$i]) % 256;
            $x = $s[$i];
            $s[$i] = $s[$j];
            $s[$j] = $x;
            $res .= $str[$y] ^ \chr($s[($s[$i] + $s[$j]) % 256]);
        }

        return $res;
    }
177720
public function remove(string $cypher): self
    {
        $query = new self;
        $query->clauses = $this->clauses->add(
            new Clause\RemoveClause($cypher)
        );

        return $query;
    }
564187
protected function generateIdentifier($prefix, $maxLength)
    {
        $hash = null;
        $dictionary = 'abcdefghijklmnopqrstuvwxyz0123456789';

        for ($i = 0; $i < ($maxLength - strlen($prefix)); $i++) {
            $hash .= $dictionary[mt_rand(0, strlen($dictionary) - 1)];
        }

        return $prefix.$hash;
    }
1255344
public static function gen($password)
    {
        return crypt($password, self::$algo . self::$cost . '$' . self::uniqueSalt());
    }
215315
public function generateKey()
    {
        if (extension_loaded('openssl')) {
            $key = openssl_random_pseudo_bytes(16);
        } else {
            // SHA1 is 128 bit (= 16 bytes)
            $key = sha1(spl_object_hash($this) . mt_rand(0, PHP_INT_MAX) . uniqid('', true), true);
        }

        return base64_encode($key);
    }
625086
private function hmacsha1(string $key, string $message): string
    {
        if (function_exists('hash_hmac')) {
            return hash_hmac('sha1', $message, $key, true);
        }

        $blocksize = 64;
        if (strlen($key) > $blocksize) {
            $key = pack('H*', sha1($key));
        }
        $key = str_pad($key, $blocksize, chr(0x00));
        $ipad = str_repeat(chr(0x36), $blocksize);
        $opad = str_repeat(chr(0x5c), $blocksize);
        $hmac = pack('H*', sha1(($key ^ $opad).pack('H*', sha1(($key ^ $ipad).$message))));

        return $hmac;
    }
78523
public function generateBase32RandomKey($length = 16, $prefix = '')
    {
        $secret = $prefix ? $this->toBase32($prefix) : '';

        $secret = $this->strPadBase32($secret, $length);

        $this->validateSecret($secret);

        return $secret;
    }
506428
public function orderBy(
        string $cypher,
        string $direction = 'ASC'
    ): self {
        $direction = \strtolower($direction);

        $query = new self;
        $query->clauses = $this->clauses->add(
            Clause\OrderByClause::$direction($cypher)
        );

        return $query;
    }