代码之家  ›  专栏  ›  技术社区  ›  Jason McCreary

CakePHP 1.3.0 Cookie值未解密

  •  1
  • Jason McCreary  · 技术社区  · 15 年前

    write() . 我的假设是,它们是自动解密的 read() . 我好像找不到 在文件里。

    我已经相应地为Cookie组件设置了密钥。

    $this->Cookie->key = 'qs#$XOw!';
    
    2 回复  |  直到 15 年前
        1
  •  3
  •   nateritter    15 年前

    如果你安装了Suhosin安全补丁,由于某种原因解密根本不起作用。提交问题和潜在解决方案: http://groups.google.com/group/cake-php/browse_thread/thread/7e6cda2e03a7c54/b685c58394d86f50?lnk=gst&q=decrypt+cookie#b685c58394d86f50

        2
  •  0
  •   Chris Jacob    13 年前

    添加了rijndael加密类型。这为我解决了问题。

    http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html

    历史记录:

    http://cakephp.lighthouseapp.com/projects/42648/tickets/471-securitycipher-function-cannot-decrypt

    class AppController extends Controller {
    
        function beforeFilter() 
        {
            // Using "rijndael" encryption because the default "cipher" type of encryption fails to decrypt when PHP has the Suhosin patch installed. 
            // See: http://cakephp.lighthouseapp.com/projects/42648/tickets/471-securitycipher-function-cannot-decrypt
            $this->Cookie->type('rijndael');
    
            // When using "rijndael" encryption the "key" value must be longer than 32 bytes.
            $this->Cookie->key = 'qSI2423424ASadsadasd2131242334SasdadAWQEAv!@*(XSL#$%)asGb$@11~_+!@#HKis~#^';
    
            // Works
            $result = $this->Cookie->read('Test.rijndael');
            var_dump($result);
            $this->Cookie->write('Test.rijndael', 'foo');
    
            // Fails
            $this->Cookie->type('cipher');
            $result = $this->Cookie->read('Test.cipher');
            var_dump($result);
            $this->Cookie->write('Test.cipher', 'foo');
        }
    }