Skip to content

drjele/symfony-doctrine-encrypt

Repository files navigation

Doctrine encrypt

NO LONGER MAINTAINED, MOVED TO https://gitlab.com/precision-soft-open-source/symfony/doctrine-encrypt

The bundle will automatically register the types from \Drjele\Doctrine\Encrypt\Type as Doctrine types.

It can be used for any string field.

You may fork and modify it as you wish.

Contributions are welcomed.

Purpose

Encrypt and decrypt data using Doctrine.

I am trying to solve a few problems that i found with the current offerings:

  • Have encrypt and decrypt available if using entities or just selecting fields.
  • Easy where (for the moment the parameters have to be encrypted before setting them).

Usage

  • The value on the entity will always be unencrypted.
  • The purpose for AES256FixedEncryptor, AES256FixedType pair is to be able to use WHERE, as it will always return the same result for the same input.
  • EntityService::getEncryptor() will return the encryptor used for the field, if you need to encrypt a value to use it as a WHERE parameter.
  • Inside entity:
class Customer
{
    /**
     * @ORM\Column(type="encryptedAES256")
     */
    private string $name;

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }
}
  • To encrypt an unencrypted database:
php bin/console drjele:doctrine:database:encrypt
  • To decrypt an encrypted database:
php bin/console drjele:doctrine:database:decrypt

Dev

git clone git@gitlab.com:drjele-symfony/doctrine-encrypt.git
cd doctrine-encrypt

rm -rf .git/hooks && ln -s ../dev/git-hooks .git/hooks

./dc build && ./dc up -d

Todo

  • Easy where, pass the unencrypted params and have them automatically encrypt.
  • Configure registered encryptors.
  • Have a isEncrypted($entity, $fieldName): bool method.
  • Unit tests.

Inspired by