generalpiston / typeorm-encrypted

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

conditionally encryption columns #70

Closed basz closed 3 months ago

basz commented 3 months ago

I would like a way to conditionally encrypt columns

specifically I have a key value table (used to store in this case some sort of preferences). Dependant on the value of the key the value colums should or shouldn't be encrypted.

I image that a callback with the entity as argument could be added to the options that enables or disabled the encryption without much trouble?

Would such a feature be appreciated?

encrypt: {
      key: "d85117047fd06d3afa79b6e44ee3a52eb426fc24c3a2e3667732e8da0342b4da",
      algorithm: "aes-256-gcm",
      ivLength: 16,
      enabled: (entity: MyEntity) => entity.key === 'apiKey',
    }
generalpiston commented 3 months ago

@basz seems super useful. Encryption happens client-side, so it makes sense.

I'm a bit short on time these days... so if you want to jump in and add it... feel free :). I can definitely do reviews.

basz commented 3 months ago

sure, it will be fun... just gove me a few days as I'm swamped atm

basz commented 3 months ago

Encryption happens client-side, so it makes sense.

What do you mean by that remark? Seems your have two distinct conditions for encryption and decryption.