plenta / contao-encryption
已移除的Contao加密类的替代服务。
Requires
- php: ^7.4 || ^8.0
- contao/core-bundle: ^4.4
- phpseclib/phpseclib: ^3.0.14
Requires (Dev)
- contao/manager-bundle: ^4.4
- contao/test-case: ^4.0.0
- friendsofphp/php-cs-fixer: ^v3.4.0
- phpseclib/phpseclib2_compat: 1.0.4
- phpunit/phpunit: ^9.5.2
- squizlabs/php_codesniffer: ^3.5.4
- symfony/phpunit-bridge: ^4
Conflicts
- contao/manager-plugin: <2.0 || >=3.0
Replaces
- brkwsky/contao-encryption: 2.2.0
README
Contao Encryption
已弃用的Contao加密类(Contao\Encryption)的替代服务。
请在使用dca回调或加密服务之前设置加密密钥。
使用Contao Manager安装
搜索encryption,您将找到此扩展。
使用Composer安装
composer require plenta/contao-encryption
升级到3.0.0及以上版本
自plenta/contao-encryption 3.0.0以来,底层phpseclib扩展已升级到版本3。
phpseclib 2会将加密密钥截断为56个字符,而phpseclib 3不会截断加密密钥。
有一个新的参数plenta_contao_encryption.truncate_encryption_key
来保持扩展与旧版本兼容。默认值为true
。这意味着加密仍然像phpseclib2一样工作。如果您想使用更长的加密密钥,必须将plenta_contao_encryption.truncate_encryption_key
参数设置为false
。
如果您将plenta_contao_encryption.truncate_encryption_key
参数设置为false
,并且您已在系统中使用超过56个字符的加密密钥加密了数据,您将无法解密数据。
加密密钥
请仔细阅读,否则您可能会丢失所有加密数据!
此扩展使用默认的加密密钥%kernel.secret%
。Symfony建议定期更改%kernel.secret%
。因此,强烈建议为此扩展设置一个专用的加密密钥。
截断加密密钥
phpseclib 2会将加密密钥截断为56个字符,而phpseclib 3不会截断加密密钥。
参数plenta_contao_encryption.truncate_encryption_key
是在3.0.0版本中引入的,以保持扩展与旧版本兼容。默认值为true
。这意味着加密仍然像phpseclib2一样工作。如果您想使用更长的加密密钥,必须将plenta_contao_encryption.truncate_encryption_key
参数设置为false
。
如果您将plenta_contao_encryption.truncate_encryption_key
参数设置为false
,并且您已在系统中使用超过56个字符的加密密钥加密了数据,您将无法解密数据。
如何设置专用的加密密钥
配置参数的名称为encryption_key
,位于plenta_contao_encryption
命名空间下。其值应是一系列随机选择的字符、数字和符号,推荐长度约为32个字符。
请备份您的加密密钥。如果您丢失了它,您将无法恢复数据。
如果您想更改加密密钥,您必须使用旧加密密钥解密所有已加密数据,然后使用新加密密钥加密。
# config/parameters.yaml or config/services.yaml plenta_contao_encryption: encryption_key: 'CharactersNumbersSymbolsAround32CharactersLong' truncate_encryption_key: true
您还可以使用环境变量。
# config/parameters.yaml or config/services.yaml plenta_contao_encryption: encryption_key: '%env(PLENTA_CONTAO_ENCRYPTION_KEY)%' truncate_encryption_key: true
# .env or .env.local PLENTA_CONTAO_ENCRYPTION_KEY="CharactersNumbersSymbolsAround32CharactersLong"
示例 > DCA
// tl_member $GLOBALS['TL_DCA']['tl_member']['fields']['bank_iban'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_member']['bank_iban'], 'exclude' => true, 'inputType' => 'text', 'eval' => [ 'mandatory' => false, 'maxlength' => 32, 'tl_class' => 'w50', 'feEditable' => true, 'feGroup' => 'bank' ], 'load_callback' => [ ['plenta.encryption', 'decrypt'] ], 'save_callback' => [ ['plenta.encryption', 'encrypt'] ], 'sql' => "varchar(32) NOT NULL default ''" ];
示例 > URL参数
$encryptionService = \Contao\System::getContainer()->get('plenta.encryption'); $urlParameter = $encryptionService->encryptUrlSafe('value'); $urlGetParameter = \Contao\Input::get('parameter'); $encryptionService->decryptUrlSafe($urlGetParameter);