socfest / encrypted-types
1.1
2021-02-23 12:18 UTC
Requires
- php: ^7.1.3|^8.0
- ext-openssl: *
- symfony/config: ^3.4 || ^4.0 || ^5.0
- symfony/dependency-injection: ^3.4 || ^4.0 || ^5.0
- symfony/http-kernel: ^3.4 || ^4.0 || ^5.0
Requires (Dev)
- phpunit/phpunit: ^8.0
Suggests
- doctrine/doctrine-bundle: For use with Doctrine ORM
- doctrine/mongodb-odm-bundle: For use with Doctrine ODM
README
Store database data encrypted
Encryption methods:
- base64
- openssl
Install
Require package via composer
composer require socfest/encrypted-types
Init bundle in bundles.php
# config/bundles.php
return [
// for ODM
Socfest\MongoDB\SocfestMongoEncryptedTypesBundle::class => ['all' => true],
//for ORM
Socfest\ORM\SocfestORMEncryptedTypesBundle::class => ['all' => true],
]
You can specify the openssl cipher method by enter this to .env file.
See the php.net openssl_cipher_iv_length page (https://www.php.net/manual/en/function.openssl-cipher-iv-length.php)
OPENSSL_CIPHER=%cipher_method%
Usage
ODM
In the model you can specify the field type. The new encrypted types are:
- encrypted_openssl
- encrypted_base64
/**
* @var string
* @MongoDB\Field(type="encrypted_openssl")
*/
protected $fullName;
In query you can find by full value, and you have to encrypt before set to equals.
Don't forget to use the correct encrypter!
$this->dm->getRepository(User::class)
->createQueryBuilder()
->field('fullName')
->equals(OpenSSLEncrypter::encrypt('X Y'))
->getQuery()
->execure()
);
also work with find methods
$this->dm->getRepository(User::class)
->findOneBy([
'fullName' => OpenSSLEncrypter::encrypt('X Y')
])