バイト列を暗号化します。

@param	binary	$byte		バイナリ
@param	string	$key		暗号化キー
@param	array	$options	暗号化オプション
@return	string	暗号化されたバイナリ
183106
public static function EncryptByteStream ($byte, $key, $options = []) {
		$options['module'] = static::DEFAULT_BYTE_STREAM_CIPHER_METHODS;
		$options = static::_AdjustOptions($options);
		return openssl_encrypt($byte, $options['method'], $key, $options['openssl_options'], $options['iv']);
	}
642807
public static function Decrypt ($data, $key, $options = []) {
		$options = static::_AdjustOptions($options);
		$td = static::_OpenMcrypt($key, $options);
		$data = @mdecrypt_generic($td, $data);
		static::_CloseMcrypt($td);

		$pad = ord($data{strlen($data) - 1});
		if ($pad > strlen($data)) {
			return false;
		}

		if (strspn($data, chr($pad), strlen($data) - $pad) != $pad) {
			return false;
		}

		return substr($data, 0, -1 * $pad);
	}
226892
public static function encrypt($bytesIn, $mode, $key, $size, $iv){
		if(count($key)%$size)
		{
			throw new Exception('Key length does not match specified size.');
		}
		if(count($iv)%16)
		{
			throw new Exception('iv length must be 128 bits.');
		}
		// the AES input/output
		$byteArray = array();
		$input = array();
		$output = array();
		$ciphertext = array();
		$cipherOut = array();
		// char firstRound
		$firstRound = true;
		if ($bytesIn !== null)
		{
			for ($j = 0;$j < ceil(count($bytesIn)/16); $j++)
			{
				$start = $j*16;
				$end = $j*16+16;
				if($j*16+16 > count($bytesIn))
					$end = count($bytesIn);
				$byteArray = self::getPaddedBlock($bytesIn,$start,$end,$mode);
				if ($mode == self::modeOfOperation_CFB)
				{
					if ($firstRound)
					{
						$output = self::encryptBlock($iv, $key, $size);
						$firstRound = false;
					}
					else
						$output = self::encryptBlock($input, $key, $size);
					for ($i = 0; $i < 16; $i++)
						$ciphertext[$i] = $byteArray[$i] ^ $output[$i];
					for($k = 0;$k < $end-$start;$k++)
						array_push($cipherOut, $ciphertext[$k]);
					$input = $ciphertext;
				}
				else if ($mode == self::modeOfOperation_OFB)
				{
					if ($firstRound)
					{
						$output = self::encryptBlock($iv, $key, $size);
						$firstRound = false;
					}
					else
						$output = self::encryptBlock($input, $key, $size);
					for ($i = 0; $i < 16; $i++)
						$ciphertext[$i] = $byteArray[$i] ^ $output[$i];
					for($k = 0;$k < $end-$start;$k++)
						array_push($cipherOut, $ciphertext[$k]);
					$input = $output;
				}
				else if ($mode == self::modeOfOperation_CBC)
				{
					for ($i = 0; $i < 16; $i++)
						$input[$i] = $byteArray[$i] ^ (($firstRound) ? $iv[$i] : $ciphertext[$i]);
					$firstRound = false;
					$ciphertext = self::encryptBlock($input, $key, $size);
					// always 16 bytes because of the padding for CBC
					for($k = 0;$k < 16;$k++)
						array_push($cipherOut, $ciphertext[$k]);
				}
			}
		}
		return array('mode' => $mode, 'originalsize' => count($bytesIn), 'cipher' => $cipherOut);
	}
1034649
public byte[] readBlob(String key) throws IOException, KeyNotFoundException{
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        readBlobTo(key, out);
        byte[] bytes = out.toByteArray();
        out.close();
        return bytes;
    }
84864
public static function sortByKeyString($a, $b, $key) {
    $a_title = (is_array($a) && isset($a[$key])) ? $a[$key] : '';
    $b_title = (is_array($b) && isset($b[$key])) ? $b[$key] : '';

    return strnatcasecmp($a_title, $b_title);
  }
152559
public function toJson($key = null, $options = 0)
    {
        if (is_string($key)) {
            return json_encode($this->get($key), $options);
        }
        $options = $key === null ? 0 : $key;
        return json_encode($this->elements, $options);
    }
343533
public function get_key( $key = '', $is_option = false ) {
		if ( true === $is_option ) {
			return $this->option_prefix . $key . $this->option_surfix;
		}

		return $this->transient_prefix . $key . $this->transient_surfix;
	}
243286
public function decrypt($cipher, $key = 'des_key', $base64 = true)
    {
        if (!$cipher) {
            return '';
        }

        $cipher  = $base64 ? base64_decode($cipher) : $cipher;
        $ckey    = $this->config->get_crypto_key($key);
        $method  = $this->config->get_crypto_method();
        $opts    = defined('OPENSSL_RAW_DATA') ? OPENSSL_RAW_DATA : true;
        $iv_size = openssl_cipher_iv_length($method);
        $iv      = substr($cipher, 0, $iv_size);

        // session corruption? (#1485970)
        if (strlen($iv) < $iv_size) {
            return '';
        }

        $cipher = substr($cipher, $iv_size);
        $clear  = openssl_decrypt($cipher, $method, $ckey, $opts, $iv);

        return $clear;
    }
282745
public static function supported($key, $cipher)
    {
        if (! in_array($cipher, static::$cipherSupported)) {
            return false;
        }

        $length = mb_strlen($key, '8bit');

        return ($cipher === 'AES-128-CBC' && $length === 16) ||
        ($cipher === 'AES-256-CBC' && $length === 32);
    }
645914
public function del($key, array $options = [])
    {
        $params = [
            'key' => $key,
        ];
        $params = $this->encode($params);
        $options = $this->encode($options);
        $body = $this->request(self::URI_DELETE_RANGE, $params, $options);
        $body = $this->decodeBodyForFields(
            $body,
            'prev_kvs',
            ['key', 'value',]
        );

        if (isset($body['prev_kvs']) && $this->pretty) {
            return $this->convertFields($body['prev_kvs']);
        }

        return $body;
    }
810957
public function t($key, array $options = [], $locale = null)
    {
        if (strpos($key, '.') === 0) {
            $key = str_replace('/', '.', $this->template->prefix()) . $key;
        }
        
        $i18n = $this->actionView->getService('i18n');
        $options['exception'] = true;
        
        try {
            $tr = $i18n->translate($key, $options, $locale);
        } catch (TranslationMissingException $e) {
            $parts = explode('.', $key);
            $title = $this->actionView->getService('inflector')->titleize(end($parts));
            $tr = sprintf(
                '<span class="translation_missing" title="translation missing: %s">%s</span>',
                $i18n->defaultLocale() . '.' . $key,
                $title
            );
        }
        
        return $tr;
    }
719665
public function bitPos($key, $bit, $start = null, $end = null) {
        $payload = ['bitpos', $key, $bit];

        if ($start !== null) {
            $payload[] = $start;

            if ($end !== null) {
                $payload[] = $end;
            }
        }

        return $this->send($payload);
    }
690141
public static void validateKey(final String key, final boolean binary) {
    byte[] keyBytes = KeyUtil.getKeyBytes(key);
    int keyLength = keyBytes.length;

    if (keyLength > MAX_KEY_LENGTH) {
      throw KEY_TOO_LONG_EXCEPTION;
    }

    if (keyLength == 0) {
      throw KEY_EMPTY_EXCEPTION;
    }

    if(!binary) {
      for (byte b : keyBytes) {
        if (b == ' ' || b == '\n' || b == '\r' || b == 0) {
          throw new IllegalArgumentException(
              "Key contains invalid characters:  ``" + key + "''");
        }
      }
    }

  }
598268
protected function assertRequiredOptions($key, array $options)
    {
        $missing = array_diff_key(array_flip($this->getRequiredOptions($key)), $options);
        if (!empty($missing)) {
            throw new \InvalidArgumentException(
                '参数不完整，请指定'.$key.'参数: '.implode(', ', array_keys($missing))
            );
        }
    }
1059448
public static function supported($key, $cipher)
    {
        $length = mb_strlen($key, '8bit');

        return ((($cipher === 'AES-128-CBC') && ($length === 16)) || (($cipher === 'AES-256-CBC') && ($length === 32)));
    }
1021514
public static function EncryptByteStream ($byte, $key, $options = []) {
		$options['module'] = \MCRYPT_MODE_CFB;
		return static::Encrypt($byte, $key, $options);
	}
583976
protected function parseKey($key, $options = [])
    {
        $key = trim($key);
        if (strpos($key, '$.') && false === strpos($key, '(')) {
            // JSON字段支持
            list($field, $name) = explode('$.', $key);
            $key                = 'json_extract(' . $field . ', \'$.' . $name . '\')';
        } elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) {
            list($table, $key) = explode('.', $key, 2);
            if ('__TABLE__' == $table) {
                $table = $this->query->getTable();
            }
            if (isset($options['alias'][$table])) {
                $table = $options['alias'][$table];
            }
        }
        if (!preg_match('/[,\'\"\*\(\)`.\s]/', $key)) {
            $key = '`' . $key . '`';
        }
        if (isset($table)) {
            if (strpos($table, '.')) {
                $table = str_replace('.', '`.`', $table);
            }
            $key = '`' . $table . '`.' . $key;
        }
        return $key;
    }