Encrypts a block

@access private
@param String $in
@return String
437019
function _encryptBlock($in)
    {
        $state = array();
        $words = unpack('N*word', $in);

        $w = $this->w;
        $t0 = $this->t0;
        $t1 = $this->t1;
        $t2 = $this->t2;
        $t3 = $this->t3;
        $Nb = $this->Nb;
        $Nr = $this->Nr;
        $c = $this->c;

        // addRoundKey
        $i = 0;
        foreach ($words as $word) {
            $state[] = $word ^ $w[0][$i++];
        }

        // fips-197.pdf#page=19, "Figure 5. Pseudo Code for the Cipher", states that this loop has four components - 
        // subBytes, shiftRows, mixColumns, and addRoundKey. fips-197.pdf#page=30, "Implementation Suggestions Regarding 
        // Various Platforms" suggests that performs enhanced implementations are described in Rijndael-ammended.pdf.
        // Rijndael-ammended.pdf#page=20, "Implementation aspects / 32-bit processor", discusses such an optimization.
        // Unfortunately, the description given there is not quite correct.  Per aes.spec.v316.pdf#page=19 [1], 
        // equation (7.4.7) is supposed to use addition instead of subtraction, so we'll do that here, as well.

        // [1] http://fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.v316.pdf
        $temp = array();
        for ($round = 1; $round < $Nr; $round++) {
            $i = 0; // $c[0] == 0
            $j = $c[1];
            $k = $c[2];
            $l = $c[3];

            while ($i < $this->Nb) {
                $temp[$i] = $t0[$state[$i] & 0xFF000000] ^ 
                            $t1[$state[$j] & 0x00FF0000] ^ 
                            $t2[$state[$k] & 0x0000FF00] ^ 
                            $t3[$state[$l] & 0x000000FF] ^ 
                            $w[$round][$i];
                $i++;
                $j = ($j + 1) % $Nb;
                $k = ($k + 1) % $Nb;
                $l = ($l + 1) % $Nb;
            }

            for ($i = 0; $i < $Nb; $i++) {
                $state[$i] = $temp[$i];
            }
        }

        // subWord
        for ($i = 0; $i < $Nb; $i++) {
            $state[$i] = $this->_subWord($state[$i]);
        }

        // shiftRows + addRoundKey
        $i = 0; // $c[0] == 0
        $j = $c[1];
        $k = $c[2];
        $l = $c[3];
        while ($i < $this->Nb) {
            $temp[$i] = ($state[$i] & 0xFF000000) ^ 
                        ($state[$j] & 0x00FF0000) ^ 
                        ($state[$k] & 0x0000FF00) ^ 
                        ($state[$l] & 0x000000FF) ^
                         $w[$Nr][$i];
            $i++;
            $j = ($j + 1) % $Nb;
            $k = ($k + 1) % $Nb;
            $l = ($l + 1) % $Nb;
        }
        $state = $temp;

        array_unshift($state, 'N*');

        return call_user_func_array('pack', $state);
    }
12053
public static function encrypt($text)
    {
        if (function_exists('mcrypt_encrypt')) {
            $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
            $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
            $len = mcrypt_get_key_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);

            /** @var \Concrete\Core\Config\Repository\Repository $config */
            $config = \Core::make('config/database');
            $text = base64_encode(mcrypt_encrypt(MCRYPT_XTEA, substr($config->get('concrete.security.token.encryption'), 0, $len), $text, MCRYPT_MODE_ECB, $iv));
        }

        return $text;
    }
1188228
function _encryptBlock($in)
    {
        static $tables;
        if (empty($tables)) {
            $tables = &$this->_getTables();
        }
        $t0   = $tables[0];
        $t1   = $tables[1];
        $t2   = $tables[2];
        $t3   = $tables[3];
        $sbox = $tables[4];

        $state = array();
        $words = unpack('N*', $in);

        $c = $this->c;
        $w = $this->w;
        $Nb = $this->Nb;
        $Nr = $this->Nr;

        // addRoundKey
        $wc = $Nb - 1;
        foreach ($words as $word) {
            $state[] = $word ^ $w[++$wc];
        }

        // fips-197.pdf#page=19, "Figure 5. Pseudo Code for the Cipher", states that this loop has four components -
        // subBytes, shiftRows, mixColumns, and addRoundKey. fips-197.pdf#page=30, "Implementation Suggestions Regarding
        // Various Platforms" suggests that performs enhanced implementations are described in Rijndael-ammended.pdf.
        // Rijndael-ammended.pdf#page=20, "Implementation aspects / 32-bit processor", discusses such an optimization.
        // Unfortunately, the description given there is not quite correct.  Per aes.spec.v316.pdf#page=19 [1],
        // equation (7.4.7) is supposed to use addition instead of subtraction, so we'll do that here, as well.

        // [1] http://fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.v316.pdf
        $temp = array();
        for ($round = 1; $round < $Nr; ++$round) {
            $i = 0; // $c[0] == 0
            $j = $c[1];
            $k = $c[2];
            $l = $c[3];

            while ($i < $Nb) {
                $temp[$i] = $t0[$state[$i] >> 24 & 0x000000FF] ^
                            $t1[$state[$j] >> 16 & 0x000000FF] ^
                            $t2[$state[$k] >>  8 & 0x000000FF] ^
                            $t3[$state[$l]       & 0x000000FF] ^
                            $w[++$wc];
                ++$i;
                $j = ($j + 1) % $Nb;
                $k = ($k + 1) % $Nb;
                $l = ($l + 1) % $Nb;
            }
            $state = $temp;
        }

        // subWord
        for ($i = 0; $i < $Nb; ++$i) {
            $state[$i] =   $sbox[$state[$i]       & 0x000000FF]        |
                          ($sbox[$state[$i] >>  8 & 0x000000FF] <<  8) |
                          ($sbox[$state[$i] >> 16 & 0x000000FF] << 16) |
                          ($sbox[$state[$i] >> 24 & 0x000000FF] << 24);
        }

        // shiftRows + addRoundKey
        $i = 0; // $c[0] == 0
        $j = $c[1];
        $k = $c[2];
        $l = $c[3];
        while ($i < $Nb) {
            $temp[$i] = ($state[$i] & 0xFF000000) ^
                        ($state[$j] & 0x00FF0000) ^
                        ($state[$k] & 0x0000FF00) ^
                        ($state[$l] & 0x000000FF) ^
                         $w[$i];
            ++$i;
            $j = ($j + 1) % $Nb;
            $k = ($k + 1) % $Nb;
            $l = ($l + 1) % $Nb;
        }

        switch ($Nb) {
            case 8:
                return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6], $temp[7]);
            case 7:
                return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6]);
            case 6:
                return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5]);
            case 5:
                return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4]);
            default:
                return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3]);
        }
    }
871420
function decryptBlock($y)
    {
        $x = ""; // 16-byte string

        // place input y into the initial state matrix in column order
        for ($i = 0; $i < 4 * $this->Nb; $i++) $this->s[$i % 4][($i - $i % $this->Nb) / $this->Nb] = ord($y[$i]);

        // add round key
        $this->addRoundKey($this->Nr);

        for ($i = $this->Nr - 1; $i > 0; $i--) {
            // inverse shift rows
            $this->invShiftRows();

            // inverse sub bytes
            $this->invSubBytes();

            // add round key
            $this->addRoundKey($i);

            // inverse mix columns
            $this->invMixColumns();
        }

        // inverse shift rows
        $this->invShiftRows();

        // inverse sub bytes
        $this->invSubBytes();

        // add round key
        $this->addRoundKey($i);

        // place state matrix s into x in column order
        for ($i = 0; $i < 4 * $this->Nb; $i++) {
            // Uncomment out the line below if your plaintext might contain
            // null characters or if you handle null characters elsewhere.
            //$x .= chr($this->s[$i%4][($i-$i%$this->Nb)/$this->Nb]);

            // Used to remove filled null characters.
            $x .= ($this->s[$i % 4][($i - $i % $this->Nb) / $this->Nb] == chr(0) ? "" : chr($this->s[$i % 4][($i - $i % $this->Nb) / $this->Nb]));
        }

        return $x;
    }
469944
public function encrypt($input)
    {
        if (! $input) {
            return $input;
        }

        $methods = $this->getEncryptionMethods();
        $method  = reset($methods);
        $mkey    = key($methods);

        if ('mcrypt' == $method) {
            $result = $this->encryptMcrypt($input);
        } elseif ('null' == $method) {
            $result = $input;
        } else {
            $result = $this->encryptOpenSsl($input, $method);
        }

        return ":$mkey:" . base64_encode($result);
    }
163250
public function encrypt($data)
    {
        try {
            return openssl_encrypt($data, self::$algorithm, self::$pass);
        } catch (\Exception $e) {
            return $data;
        }
    }
980921
public function decrypt($data){
        $data = base64_decode($data);
        $maxlength = $this->getMaxDecryptBlockSize($this->privateKey);
        $output='';
        while(strlen($data)){
            $input = substr($data, 0, $maxlength);
            $data = substr($data, $maxlength);
            openssl_private_decrypt($input, $out, $this->privateKey);
            $output .= $out;
        }
        return $output;
    }
1054689
public function encryptInteger($n) {
		if (!is_numeric($n)) return null;
		return (PHP_INT_SIZE == 4 ? self::encrypt32($n) : self::encrypt64($n)) ^ $this->encPassword;
	}
779573
static function encrypt ($pwd, $data, $ispwdHex = 0)
	{
		if ($ispwdHex)
			$pwd = @pack('H*', $pwd); // valid input, please!
 
		$key[] = '';
		$box[] = '';
		$cipher = '';
 
		$pwd_length = strlen($pwd);
		$data_length = strlen($data);
 
		for ($i = 0; $i < 256; $i++)
		{
			$key[$i] = ord($pwd[$i % $pwd_length]);
			$box[$i] = $i;
		}
		for ($j = $i = 0; $i < 256; $i++)
		{
			$j = ($j + $box[$i] + $key[$i]) % 256;
			$tmp = $box[$i];
			$box[$i] = $box[$j];
			$box[$j] = $tmp;
		}
		for ($a = $j = $i = 0; $i < $data_length; $i++)
		{
			$a = ($a + 1) % 256;
			$j = ($j + $box[$a]) % 256;
			$tmp = $box[$a];
			$box[$a] = $box[$j];
			$box[$j] = $tmp;
			$k = $box[(($box[$a] + $box[$j]) % 256)];
			$cipher .= chr(ord($data[$i]) ^ $k);
		}
		return $cipher;
	}
303219
public function encrypt($token)
    {
        return urlencode(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($this->key), $token, MCRYPT_MODE_CBC, md5(md5($this->key)))));
    }
706021
public function encrypt($encrypt, $key)
    {
        $inputParams = [
            'encrypt' => $encrypt,
            'key'     => $key,
        ];
        $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($inputParams));
        $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND);
        $this->debug->debug(__FUNCTION__, 'IV Key: ' . json_encode($iv));
        $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, pack("H*", $key), $encrypt, MCRYPT_MODE_ECB, $iv));
        $this->debug->info(__FUNCTION__, 'encrypt Result: ' . json_encode($encrypted));

        return $encrypted;
    }
467723
public function decrypt($encrypted) {
    return trim(
                mcrypt_decrypt(
                               MCRYPT_RIJNDAEL_256,
                               $this->password,
                               base64_decode($encrypted),
                               MCRYPT_MODE_ECB,
                               mcrypt_create_iv(
                                                mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
                                                MCRYPT_RAND
                                                )
                               )
                );
  }
1253292
public function encrypt($value)
    {
        $iv = Str::randomBytes($this->getIvSize());

        $value = \openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);

        if ($value === false) {
            throw new EncryptException('Could not encrypt the data.');
        }

        $mac = $this->hash($iv = base64_encode($iv), $value);

        return base64_encode(json_encode(compact('iv', 'value', 'mac')));
    }
818143
protected function encrypt($value)
    {
        return $this->getCryptService()->encrypt(serialize($value), $this->getSecurity()->getPrivateKey());
    }
87240
public function encrypt(string $decrypted): string {
        $status = openssl_public_encrypt($decrypted, $encrypted, $this);
        if(!$status) {
            throw new RuntimeException('Encrypt failed');
        }
        return $encrypted;
    }
995831
protected function _encrypt(string $kek, string $block): string
    {
        $str = openssl_encrypt($block, $this->_cipherMethod(), $kek,
            OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
        if (false === $str) {
            throw new \RuntimeException(
                "openssl_encrypt() failed: " . $this->_getLastOpenSSLError());
        }
        return $str;
    }
131859
public static function encrypt($keyinfo, $payload=array())
	{
		if (isset($keyinfo->secret) && isset($keyinfo->hash) && function_exists('mcrypt_encrypt')) {
			$encrypted = trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $keyinfo->secret, json_encode($payload), MCRYPT_MODE_NOFB, $keyinfo->hash)));
		} else {
			$encrypted = null;
		}
		return $encrypted;
	}