CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 纪念品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • Bakery
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助与支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Middleware
      • Session
      • TestSuite
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 EncryptedCookieMiddleware

用于加密和解密 Cookie 的中间件。

此中间件层将使用给定的密钥和密码类型对命名 Cookie 进行加密/解密。为了支持多个密钥/密码类型,可以使用此中间件多次。

请求数据中的 Cookie 将被解密,而响应头中的 Cookie 将自动加密。如果响应是 {@link \Cake\Http\Response},则使用 withCookie() 和 `cookie()`` 设置的 Cookie 数据也将被加密。

加密类型和填充与 CookieComponent 为向后兼容性使用的类型兼容。

命名空间: Cake\Http\Middleware

属性摘要

  • $_validCiphers 受保护
    list<string>

    加密 Cookie 的有效密码名称。

  • $cipherType 受保护
    string

    加密类型。

  • $cookieNames 受保护
    list<string>

    要加密/解密的 Cookie 列表

  • $key 受保护
    string

    要使用的加密密钥。

方法摘要

  • __construct() 公共

    构造函数

  • _checkCipher() 受保护

    用于验证加密密码名称的辅助方法。

  • _decode() 受保护

    解码和解密单个值。

  • _decrypt() 受保护

    使用 Security 类中的公共 $type 方法解密 $value

  • _encrypt() 受保护

    使用 Security 类中的公共 $type 方法加密 $value

  • _explode() 受保护

    爆炸方法,从 CookieComponent::_implode() 中设置的字符串返回数组。保持与 1.x CookieComponent::_implode() 的向后兼容性。

  • _getCookieEncryptionKey() 受保护

    获取 Cookie 加密密钥。

  • _implode() 受保护

    合并方法以保持键为多维数组

  • decodeCookies() 受保护

    从请求中解码 Cookie。

  • encodeCookies() 受保护

    从响应的 CookieCollection 中编码 Cookie。

  • encodeSetCookieHeader() 受保护

    从响应的 Set-Cookie 头中编码 Cookie

  • process() 公共

    应用 Cookie 加密/解密。

方法详情

__construct() ¶ 公共

__construct(list<string> $cookieNames, string $key, string $cipherType = 'aes')

构造函数

参数
list<string> $cookieNames

应该对其值进行加密的 Cookie 名称列表。

string $key

要使用的加密密钥。

string $cipherType 可选

要使用的密码类型。默认为 'aes'。

_checkCipher() ¶ 受保护

_checkCipher(string $encrypt): void

用于验证加密密码名称的辅助方法。

参数
string $encrypt

密码名称。

返回
void
抛出
RuntimeException
当提供无效的密码时。

_decode() ¶ 受保护

_decode(string $value, string|false $encrypt, string|null $key): array|string

解码和解密单个值。

参数
string $value

要解码和解密的值。

string|false $encrypt

要使用的加密密码。

string|null $key

如果指定,用作安全盐。

返回
array|string

_decrypt() ¶ 受保护

_decrypt(list<string>|string $values, string|false $mode, string|null $key = null): array|string

使用 Security 类中的公共 $type 方法解密 $value

参数
list<string>|string $values

要解密的值

string|false $mode

加密模式

string|null $key 可选

如果指定,用作安全盐。

返回
array|string

_encrypt() ¶ 受保护

_encrypt(array|string $value, string|false $encrypt, string|null $key = null): string

使用 Security 类中的公共 $type 方法加密 $value

参数
array|string $value

要加密的值

string|false $encrypt

要使用的加密模式。False 禁用加密。

string|null $key 可选

如果指定,用作安全盐。

返回
string

_explode() ¶ 受保护

_explode(string $string): array|string

爆炸方法,从 CookieComponent::_implode() 中设置的字符串返回数组。保持与 1.x CookieComponent::_implode() 的向后兼容性。

参数
string $string

包含 JSON 编码数据或裸字符串的字符串。

返回
array|string

_getCookieEncryptionKey() ¶ 受保护

_getCookieEncryptionKey(): string

获取 Cookie 加密密钥。

CookieCryptTrait 实现的一部分。

返回
string

_implode() ¶ 受保护

_implode(array $array): string

合并方法以保持键为多维数组

参数
array $array

键值映射

返回
string

decodeCookies() ¶ 受保护

decodeCookies(Psr\Http\Message\ServerRequestInterface $request): Psr\Http\Message\ServerRequestInterface

从请求中解码 Cookie。

参数
Psr\Http\Message\ServerRequestInterface $request

要从中解码 Cookie 的请求。

返回
Psr\Http\Message\ServerRequestInterface

encodeCookies() ¶ 受保护

encodeCookies(Cake\Http\Response $response): Cake\Http\Response

从响应的 CookieCollection 中编码 Cookie。

参数
Cake\Http\Response $response

要编码 Cookie 的响应。

返回
Cake\Http\Response

encodeSetCookieHeader() ¶ 受保护

encodeSetCookieHeader(Psr\Http\Message\ResponseInterface $response): Psr\Http\Message\ResponseInterface

从响应的 Set-Cookie 头中编码 Cookie

参数
Psr\Http\Message\ResponseInterface $response

要编码 Cookie 的响应。

返回
Psr\Http\Message\ResponseInterface

process() ¶ 公共

process(ServerRequestInterface $request, RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterface

应用 Cookie 加密/解密。

处理传入的服务器请求以生成响应。如果无法自行生成响应,它可能会委托给提供的请求处理程序来执行此操作。

参数
ServerRequestInterface $request

请求。

RequestHandlerInterface $handler

请求处理程序。

返回
Psr\Http\Message\ResponseInterface

属性详情

$_validCiphers ¶ 受保护

加密 Cookie 的有效密码名称。

类型
list<string>

$cipherType ¶ 受保护

加密类型。

类型
string

$cookieNames ¶ 受保护

要加密/解密的 Cookie 列表

类型
list<string>

$key ¶ 受保护

要使用的加密密钥。

类型
string
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • Bakery
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助与支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成