mogilvie / EncryptBundle

Encryption bundle
82 stars 27 forks source link

Encrypted values get re-encrypted #18

Closed Volmarg closed 3 years ago

Volmarg commented 3 years ago

So, it seems and most definitely is that You the bundle simply encrypts the value no matter if it was encrypted or not. I found and issue when I did this:

So the timeout happens because the B encrypts tones of the data again. Imported data is not working since the already encrypted data get's re-encrypted.

Volmarg commented 3 years ago

Got to close this actually, there is still something wrong, will add new one once i figure out what's going on.

mogilvie commented 3 years ago

Hi Volmarg, the encryptor checks for null values, objects and any encrypted values (those with the \<ENC> suffix) before it will actually encrypt. If any of these cases are true it just returns the data or throws an exception.

    public function encrypt($data)
    {
        // If not data return data (null)
        if (is_null($data)) {
            return $data;
        }

        if (is_object($data)) {
            throw new EncryptException('You cannot encrypt an object.',  $data);
        }

        // If the value already has the suffix <ENC> then ignore.
        if(DoctrineEncryptSubscriberInterface::ENCRYPTED_SUFFIX === substr($data, -5)) {
            return $data;
        }
...
}