generalpiston / typeorm-encrypted

Encrypted field for typeorm.
MIT License
74 stars 19 forks source link

Doesnt work inside QueryBuilder #41

Closed arcziby closed 2 years ago

arcziby commented 2 years ago

It doesn't work when i want to get value by QueryBuilder

this.userRepository
      .createQueryBuilder('user')
      .where('user.email = :email', { email })
      .getOne();
  @Column({
    type: 'varchar',
    nullable: false,
    transformer: new EncryptionTransformer({
      key: 'e41c966f21f9e1577802463f8924e6a3fe3e9751f201304213b2f845d8841d61',
      algorithm: 'aes-256-cbc',
      ivLength: 16,
      iv: 'ff5ac19190424b1d88f9419ef949ae56',
    }),
  })
  email: string;
generalpiston commented 2 years ago

I just wrote a test case for this and it appears to work: https://app.circleci.com/pipelines/github/generalpiston/typeorm-encrypted/28/workflows/9d036039-a719-42c8-bf81-fc06d012107a/jobs/55.

What does your data look like? How are you adding records?

Take a peek at the test cases to see examples of how to use this library: https://github.com/generalpiston/typeorm-encrypted/tree/c3119c043a9b4d1796544196b397d5f1ed4f6488/test

arcziby commented 2 years ago

Could you please write test case where you select data with conditional where and pass simple (no encrypted) value, for example i have encrypted emails in database but i'd like select user by email SELECT user WHERE user.email = 'a@a.eu'

generalpiston commented 2 years ago

Ahh... I see... I don't think we can handle that case. Unfortunately, typeorm lets you use transformers for storing and fetching columns, but not filtering (or other more complicated SQL).

See https://github.com/generalpiston/typeorm-encrypted/#why-wont-complex-queries-work.

Sorry man :(

arcziby commented 2 years ago

ok, so maybe you can add new tool for encrypt some value and later i just const encryptedemail = encrypt(email); SELECT user WHERE user.email = encryptedemail