I want to store data from users so that they become useless, even if the database somehow leaked. I also do not want to be able to encrypt data, so I encrypt all my data with `openssl_encrypt 'as follows:
$passCode = base64_encode($this->get('session')->get('_pk')); if (strlen($passCode) <= 16) { $iv = str_pad($passCode, 16, '0'); } else { $iv = substr($passCode, 0, 16); } $ciphertext = openssl_encrypt('whatevervalue', 'AES-256-CBC', $passCode, 0, $iv); $test = new Test(); $test->setValue($ciphertext); ... $em->persist($test); $em->flush(); ...
$passCode is actually their password, which I entered into the var session as follows:
SecurityListener.php
<?php namespace AppBundle\Listener; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; class SecurityListener { public function __construct($security, Session $session) { $this->security = $security; $this->session = $session; } public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) { $this->session->set('_pk', base64_encode($event->getRequest()->get('_password'))); } }
2 Problems:
Saving $passCode (really don't know about sessions) is perhaps a security issue?
What happens if the user changes the password. In the current case, I will need to decrypt and re-encrypt all of its database data with a new password, so that this does not seem to be the right solution. What if he loses his password?
It may be easier to understand what I want here:
I want to encrypt all the data in my database that the user himself enters there. I want this to be a βfunctionβ that even admin (s) cannot read data without a key. I know that the latter is not 100% possible (since there will be ways to intercept passwords / keys when entering through the web interface, but at least this causes some code changes). Is anything like that possible? Any open source files I can take a look at?
Thanks!
source share