socfest/encrypted-types

Installs: 205

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Type:symfony-bundle

1.1 2021-02-23 12:18 UTC

This package is not auto-updated.

Last update: 2024-04-25 04:43:55 UTC


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')
    ])