Skip to content

Commit d6260a1

Browse files
javiereguiluzxabbuh
authored andcommitted
Use OpenSSL instead of Mcrypt in the examples
1 parent 9671b95 commit d6260a1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

session/proxy_examples.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,22 @@ guest sessions.
8787
Encryption of Session Data
8888
--------------------------
8989

90-
If you wanted to encrypt the session data, you could use the proxy to encrypt
91-
and decrypt the session as required::
90+
If you want to encrypt the session data, you can use the proxy to encrypt and
91+
decrypt the session as required. The following example uses the `php-encryption`_
92+
library, but you can adapt it to any other library that you may be using::
9293

9394
// src/AppBundle/Session/EncryptedSessionProxy.php
9495
namespace AppBundle\Session;
9596

97+
use Defuse\Crypto\Crypto;
98+
use Defuse\Crypto\Key;
9699
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
97100

98101
class EncryptedSessionProxy extends SessionHandlerProxy
99102
{
100103
private $key;
101104

102-
public function __construct(\SessionHandlerInterface $handler, $key)
105+
public function __construct(\SessionHandlerInterface $handler, Key $key)
103106
{
104107
$this->key = $key;
105108

@@ -110,12 +113,12 @@ and decrypt the session as required::
110113
{
111114
$data = parent::read($id);
112115

113-
return mcrypt_decrypt(\MCRYPT_3DES, $this->key, $data);
116+
return Crypto::decrypt($data, $this->key);
114117
}
115118

116119
public function write($id, $data)
117120
{
118-
$data = mcrypt_encrypt(\MCRYPT_3DES, $this->key, $data);
121+
$data = Crypto::encrypt($data, $this->key);
119122

120123
return parent::write($id, $data);
121124
}
@@ -154,3 +157,5 @@ can intercept the session before it is written::
154157
return parent::write($id, $data);
155158
}
156159
}
160+
161+
.. _`php-encryption`: https://github.com/defuse/php-encryption

0 commit comments

Comments
 (0)