S
S
SeiLove2018-03-07 17:21:10
symfony
SeiLove, 2018-03-07 17:21:10

How to encrypt a session in symfony?

Hello! I'm trying to use a proxy as per the documentation for a given task. But for some reason nothing happens. Perhaps I forgot to register something additionally somewhere? Has anyone encountered such a problem?
Proxy code (one to one with documentation):

namespace SecurityBundle\Session;
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;

class EncryptedSessionProxy extends SessionHandlerProxy
{
    private $key;

    public function __construct( \SessionHandlerInterface $handler, $key)
    {
        $this->key = $key;

        parent::__construct($handler);
    }

    public function read($id)
    {
        $data = parent::read($id);

        return mcrypt_decrypt(\MCRYPT_3DES, $this->key, $data,'ecb');
    }

    public function write($id, $data)
    {  
        $data = mcrypt_encrypt(\MCRYPT_3DES, $this->key, $data,'ecb');

        return parent::write($id, $data);
    }

}

My configuration in services
security.encrypt_native_session:
        class: SecurityBundle\Session\EncryptedSessionProxy
        arguments: ['@session.handler.native_file','secret_string']

My config.yml
session:
        handler_id:  security.encrypt_native_session

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-03-07
@prototype_denis

Is the firewall configured correctly in security.yml, does it support sessions?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question