ywh / doctrine-encryption-extension
Doctrine2 encryption extension
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 4 567
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.5.9
- defuse/php-encryption: ^2.1
- gedmo/doctrine-extensions: ^2.4
Requires (Dev)
- doctrine/common: >=2.5.0
- doctrine/orm: >=2.5.0
- phpunit/phpunit: ^5.7
- symfony/yaml: ~2.6|~3.0
Suggests
- doctrine/orm: to use the extensions with the ORM
This package is not auto-updated.
Last update: 2024-06-09 04:03:34 UTC
README
This extension allows to encrypt entites fields using php-encryption.
This extension is based on and use Doctrine2 behavioral extensions.
Setup and autoloading
Read the documentation or check the example code on how to setup and use the extensions in most optimized way.
Encryptable Entity example:
Encryptable annotations:
- @YWH\Encryptable\Mapping\Annotation\Encryptable this class annotation tells if a class is Encryptable. Available configuration options:
- usePassword does the key is protected with a password ? Default: true
- @YWH\Encryptable\Mapping\Annotation\EncryptionKey this annotation tells that this column will contain the encryption key use to encrypt data. Only necessary when using a key protected by password
- @YWH\Encryptable\Mapping\Annotation\Encrypted this annotation tells that this column will be encrypted. Available configuration options:
- type the data type. Should one of the valid doctrine types Default: string
Notes about setting the encryption key and encrypted data columns:
EncryptionKey and Encrypted columns must be set as string type
/** * @var string * * @ORM\Column(name="encryption_key", type="text") * @YWH\EncryptionKey() */ private $encryptionKey; /** * @ORM\Column(name="encrypted_data", type="string") * @YWH\Encrypted() */ private $encryptedData;
<?php namespace Entity; use Doctrine\ORM\Mapping as ORM; use YWH\Encryptable\Mapping\Annotation as YWH; /** * @ORM\Entity * @YWH\Encryptable(usePassword=true) */ class Article { /** @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer") */ private $id; /** * @var string * * @ORM\Column(name="encryption_key", type="text") * @YWH\EncryptionKey() */ private $encryptionKey; /** * @ORM\Column(type="string", length=128) * @YWH\Encrypted() */ private $title; /** * @ORM\Column(name="date", type="string") * @YWH\Encrypted(type="datetime") */ private $date; public function getId() { return $this->id; } public function setEncryptionKey($key) { $this->encryptionKey = $key; } public function getEncryptionKey() { return $this->encryptionKey; } public function setTitle($title) { $this->title = $title; } public function getTitle() { return $this->title; } public function setDate(\DateTime $date) { $this->date = $date; } public function getDate() { return $this->date; } }