Code Monkey home page Code Monkey logo

typeorm-encrypted's Introduction

typeorm-encrypted

Encrypted field for typeorm.

Installation

npm install --save typeorm-encrypted

Example

This library can invoked in 2 ways: transformers or subscribers. In both of the examples below, the Key and IV vary based on the algorithm. See the node docs for more info.

Transformers (Recommended)

The following example has the field automatically encrypted/decrypted on save/fetch respectively.

import { Entity, Column } from "typeorm";
import { EncryptionTransformer } from "typeorm-encrypted";

@Entity()
class User {
  ...

  @Column({
    type: "varchar",
    nullable: false,
    transformer: new EncryptionTransformer({
      key: 'e41c966f21f9e1577802463f8924e6a3fe3e9751f201304213b2f845d8841d61',
      algorithm: 'aes-256-gcm',
      ivLength: 16
    })
  })
  secret: string;

  ...
}

For JSON fields you can use JSONEncryptionTransformer.

import { Entity, Column } from "typeorm";
import { EncryptionTransformer } from "typeorm-encrypted";

@Entity()
class User {
  ...

  @Column({
    type: "json",
    nullable: false,
    transformer: new JSONEncryptionTransformer({
      key: 'e41c966f21f9e1577802463f8924e6a3fe3e9751f201304213b2f845d8841d61',
      algorithm: 'aes-256-gcm',
      ivLength: 16
    })
  })
  secret: object;

  ...
}

More information about transformers is available in the typeorm docs.

Subscribers

The following example has the field automatically encrypted/decrypted on save/fetch respectively.

import { BaseEntity, Entity, Column, createConnection } from "typeorm";
import { ExtendedColumnOptions, AutoEncryptSubscriber } from "typeorm-encrypted";

@Entity()
class User extends BaseEntity {
  ...

  @Column(<ExtendedColumnOptions>{
    type: "varchar",
    nullable: false,
    encrypt: {
      key: "d85117047fd06d3afa79b6e44ee3a52eb426fc24c3a2e3667732e8da0342b4da",
      algorithm: "aes-256-gcm",
      ivLength: 16
    }
  })
  secret: string;

  ...
}

let connection = createConnection({
  ...
  entities: [ User, ... ],
  subscribers: [ AutoEncryptSubscriber, ... ]
  ...
});

Entities and subscribers can be configured via ormconfig.json and environment variables as well. See the typeorm docs for more details.

How to use a configuration file

The following example is how you can create a config stored in a separate and use it

encryption-config.ts

// it is recommended to not store encryption keys directly in config files, 
// it's better to use an environment variable or to use dotenv in order to load the value
export const MyEncryptionTransformerConfig = {
  key: process.env.ENCRYPTION_KEY,
  algorithm: 'aes-256-gcm',
  ivLength: 16
};

user.entity.ts

import { Entity, Column } from "typeorm";
import { EncryptionTransformer } from "typeorm-encrypted";
import { MyEncryptionTransformerConfig } from './encryption-config.ts'; // path to where you stored your config file

@Entity()
class User {
  // ...

  @Column({
    type: "varchar",
    nullable: false,
    transformer: new EncryptionTransformer(MyEncryptionTransformerConfig)
  })
  secret: string;

  // ...
}

It's possible to customize the config if you need to use a different ivLength or customize other fields, a brief example below

user.entity.ts

class User {
  // same as before, but for the transformer line
  @Column({
    type: "varchar",
    nullable: false,
    transformer: new EncryptionTransformer({...MyEncryptionTransformerConfig, ivLength: 24})
  })
  secret: string;
  // ...
}

FAQ

Why won't complex queries work?

Queries that transform the encrypted column wont work because transformers and subscribers operate outside of the DBMS.

What alogorithm should I use?

Unless you need to maintain compatibility with an older system (or you know exactly what you're doing), you should use "aes-256-gcm" for the mode. This means that the encryption keys are are 256 bits (32-bytes) long and that the mode of operation is GCM (Galois Counter Mode).

GCM provides both secrecy and authenticity and can generally use CPU acceleration where available.

Should I hardcode the IV?

No. Don't ever do this. It will break the encryption and is vulnerable to a "repeated nonce" attack.

If you don't provide an IV, the library will randomly generate a secure one for you.

Error: Invalid IV length

The most likely reasons you're receiving this error:

  1. Column definition is wrong. Probably an issue with the key or IV.
  2. There is existing data in your DBMS. In this case, please migrate the data.
  3. Your query cache needs to be cleared. The typeorm query cache can be cleared globally using the typeorm-cli: typeorm cache:clear. For other, more specific, solutions, see the typeorm documentation.

How can an encrypted column be added to a table with data?

Follow these steps to add an encrypted column.

  1. Add a new column (col B) to the table. Configure the column to be encrypted. Remove the transformer from the original column (col A).
  2. Write a script that queries all of the entries in the table. Set the value of col B to col A.
  3. Save all the records.
  4. Rename col A to something else manually.
  5. Rename col B to the original name of col A manually.
  6. Remove the typeorm configuration for col A.
  7. Rename the typeorm configuration for col B to col A's name.
  8. Remove col A (unencrypted column) from the table manually.

Can typeorm-encrypted encrypt the entire database?

No. This library encrypts specific fields in a database.

Popular databases like MySQL and PostgreSQL are capable of data-at-rest and in-flight encryption. Refer to your database manual to figure out how to encrypt the entirety of the database.

typeorm-encrypted's People

Contributors

andreo-k avatar basz avatar coderdan avatar dependabot[bot] avatar destreyf avatar generalpiston avatar pedronfigueiredo avatar takezoux2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

typeorm-encrypted's Issues

conditionally encryption columns

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',
    }

query with select() return not decrypted

Hello

When I do like this :

this.query->createQuery('table')
.select('SUBSTRING(table.cp, 0, 2)', 'cp')
.andSelect('COUNT(table.id)', 'nb')
....

That return good number (nb) but the result is returned (cp) the two letters but not decrypred ...
Exemple have in CP value 75011 (crypted: start by pM) and return pM not 75.

Thanks

typeorm encryption nopt working in case of unique true column

@entity()
export class UserEntity extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@column()
name: string;
@column()
age: string;
@column({
type: "varchar",
nullable: false,
unique: true,
transformer: new EncryptionTransformer({
key: 'e41c966f21f9e1577802463f8924e6a3fe3e9751f201304213b2f845d8841d61',
algorithm: 'aes-256-gcm',
ivLength: 16
})
})
email: string;
} in this case it always generate new cyper even if the email is same expected it need to throw error of duplicate please take a look at this issue

Abandoned?

Noticed the recent dependabot PR merges but your NPM repo was updated 8 months ago. Has this project been abandoned? Are you planning to push these changes to NPM any time soon?

Just wondering because it looks like a fantastic project.

[Question, help needed] How to properly retain encryption keys?

Hey there!

First of all, wanna say thanks for all your hard work in maintaining this project! it is awesome ๐Ÿ‘๐Ÿป

I am wondering if there is a way to manage encryption keys retention overtime?
Let's say I have both "old"-"new" encryption keys pair and want to update my database data,
eg encrypt data with a new key. Is there a (relatively) simple way how to do keys retention properly?

Thanks

Many to many save fails

Issue type:
[x] bug report
[x] documentation issue

Database system/driver:
[x] mysql / mariadb

TypeORM version:
[x] latest - 0.2.22

Steps to reproduce or a small repository showing the problem:

 @Override("createOneBase")
  async createOne(@ParsedRequest() req: CrudRequest, @ParsedBody() dto: Resource) {
    const location = new Location();
    location.name = "locationone";
    await getConnection().manager.save(location);
    const resource = new Resource();
    resource.color = "dogs";
    resource.locations = [location];
    await getConnection().manager.save(resource);

  }

I added a console log in the encrypt method of typeorm-encrypted/lib/transformers/index.js and here's the results


// Line 8 and 9 of index.js
//function encrypt(entity) {
//    console.log('entity', entity);


entity Location { name: 'locationname' }

entity Resource {
  color: 'dogs',
  locations: [
    Location {
      name: 'locationname',
      address: null,
      id: 15,
      createdAt: 2020-02-25T18:52:48.358Z,
      updatedAt: 2020-02-25T18:52:48.358Z
    }
  ]
}
entity undefined

// end of log for typeorm-encrypted/lib/transformers/index.js

Here's the error I get:

TypeError: Cannot read property 'constructor' of undefined
    at Object.encrypt (/Users/natedeazy/projects/MedOneScheduling/scheduling-backend/node_modules/typeorm-encrypted/lib/transformers/index.js:15:83)
    at AutoEncryptSubscriber.beforeInsert (/Users/natedeazy/projects/MedOneScheduling/scheduling-backend/node_modules/typeorm-encrypted/lib/subscribers/AutoEncryptSubscriber.js:18:24)
    at /Users/natedeazy/projects/MedOneScheduling/scheduling-backend/node_modules/typeorm/subscriber/Broadcaster.js:39:54
    at Array.forEach (<anonymous>)
    at Broadcaster.broadcastBeforeInsertEvent (/Users/natedeazy/projects/MedOneScheduling/scheduling-backend/node_modules/typeorm/subscriber/Broadcaster.js:37:53)
    at /Users/natedeazy/projects/MedOneScheduling/scheduling-backend/node_modules/typeorm/persistence/SubjectExecutor.js:162:99
    at Array.forEach (<anonymous>)
    at SubjectExecutor.broadcastBeforeEventsForAll (/Users/natedeazy/projects/MedOneScheduling/scheduling-backend/node_modules/typeorm/persistence/SubjectExecutor.js:162:33)
    at SubjectExecutor.<anonymous> (/Users/natedeazy/projects/MedOneScheduling/scheduling-backend/node_modules/typeorm/persistence/SubjectExecutor.js:68:50)
    at step (/Users/natedeazy/projects/MedOneScheduling/scheduling-backend/node_modules/tslib/tslib.js:136:27)

Add basic tests

There are 3 configurations to figure:

  1. Auto encrypt/decrypt
  2. encrypt/decrypt from utilities

Decompose autoencrypt and autodecrypt

Currently, using the AutoEncryptSubscriber automatically encrypts and decrypts fields. It would be nice to decompose these 2 and make encryption/decryption configurable.

Why not use transformers?

Why does this library use subscribers rather than plain transformers in typeorm? Was it because this came out before transformers were introduced into typeorm?

Like operator not supported

Is there a way to query based on partial words in encrypted data?

user.find({
  where: { email: ILike('%' + search + '%') }
})

Return undefined instead of null

The current implementation of the transformer returns undefined instead of null when the column is null.
Will it be better if it stick to the same return type as Typeorm.

public from(value?: string | null): string | undefined {
    if (!value) {
      return;     // Should it return value instead?
    }
    return decryptData(
      Buffer.from(value as string, 'base64'),
      this.options
    ).toString('utf8');
  }

fix issue

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/typeorm-encrypted/src/transformer.ts b/node_modules/typeorm-encrypted/src/transformer.ts
index ec5d1c8..f5f3035 100644
--- a/node_modules/typeorm-encrypted/src/transformer.ts
+++ b/node_modules/typeorm-encrypted/src/transformer.ts
@@ -2,30 +2,88 @@ import { ValueTransformer, FindOperator, In, Equal, Not } from 'typeorm';
 import { EncryptionOptions } from './options';
 import { decryptData, encryptData } from './crypto';
 
-export class EncryptionTransformer implements ValueTransformer {
+// export class EncryptionTransformer implements ValueTransformer {
+//   constructor(private options: EncryptionOptions) {}
+
+//   public from(value?: string | null | object): string | undefined {
+//     if (!value) {
+//       return;
+//     }
+
+//     return decryptData(
+//       Buffer.from(value as string, 'base64'),
+//       this.options
+//     ).toString('utf8');
+//   }
+
+//   public to(value?: string | FindOperator<any> | null): string | FindOperator<any> | undefined {
+//     if ((value ?? null) === null) {
+//       return;
+//     }
+//     if (typeof value === 'string') {
+//       return encryptData(
+//         Buffer.from(value as string, 'utf8'),
+//         this.options
+//       ).toString('base64');
+//     }
+//     if (!value) {
+//       return;
+//     }
+//     // Support FindOperator.
+//     // Just support "Equal", "In", "Not", and "IsNull".
+//     // Other operators aren't work correctly, because values are encrypted on the db.
+//     if (value.type === `in`) {
+//       return In((value.value as string[]).map(s =>
+//         encryptData(
+//           Buffer.from(s, 'utf-8'),
+//           this.options
+//         ).toString('base64')
+//       ));
+//     } else if (value.type === 'equal') {
+//       return Equal(encryptData(
+//         Buffer.from(value.value as string, 'utf-8'),
+//         this.options
+//       ).toString('base64'));
+//     } else if (value.type === 'not') {
+//       return Not(
+//         this.to(value.child ?? value.value)
+//       );
+//     } else if (value.type === 'isNull') {
+//       return value
+//     } else {
+//       throw new Error('Only "Equal","In", "Not", and "IsNull" are supported for FindOperator');
+//     }
+//   }
+// }
+
+export class JSONEncryptionTransformer implements ValueTransformer {
   constructor(private options: EncryptionOptions) {}
 
-  public from(value?: string | null): string | undefined {
+  public from(value?: string | null | object): string | undefined {
     if (!value) {
       return;
     }
 
-    return decryptData(
+    const decrypted = decryptData(
       Buffer.from(value as string, 'base64'),
       this.options
     ).toString('utf8');
+
+    return JSON.parse(decrypted);
   }
 
-  public to(value?: string | FindOperator<any> | null): string | FindOperator<any> | undefined {
+  public to(value?: any | FindOperator<any> | null): string | FindOperator<any> | undefined{
     if ((value ?? null) === null) {
       return;
     }
-    if (typeof value === 'string') {
+
+    if (typeof value === 'object' && !value.type) {
       return encryptData(
-        Buffer.from(value as string, 'utf8'),
+        Buffer.from(JSON.stringify(value) as string, 'utf8'),
         this.options
       ).toString('base64');
     }
+
     if (!value) {
       return;
     }

This issue body was partially generated by patch-package.

Issue with finding values with encrypted data

I have encrypted a column email but I can't find user that have the same email because it gives a different encryption. Is there a way to bypass that ?

I tried something like this

image

image

But without a chance.

Peer dependencies TypeORM

Hello. I'm having problem with typeorm version 0.3 as typeorm-encrypted has peer dependencies. Is it possible to adjust this?

Invalid IV length

I was trying to reproduce your examples using column transformer (just copy/paste your code) and got the error: Invalid IV length

I was able to create a new entity, but when I tried to get the data, I got that error. Any hint about this, please?

Only works with Active Record pattern

When attempting to use this library with the Data Mapper pattern, the encryption options are ignored. This is because of the following line in the transformer: entity.constructor === target && mode == "regular". When an object is passed into the save/create function, constructor does not exist.

Example:

@Entity()
class User {
    @Column(<ExtendedColumnOptions>{ type: 'varchar', name: 'name_first',
    encrypt: {
      key: "e41c966f21f9e1577802463f8924e6a3fe3e9751f201304213b2f845d8841d61",
      algorithm: "aes-256-cbc",
      ivLength: 16,
      iv: "ff5ac19190424b1d88f9419ef949ae56"
    }}) 
    firstName: string

    @Column('text', {name: 'name_last'}) 
    lastName: string
}

const userRepository = connection.getRepository(User);

await userRepository.save({ firstName: 'John', lastName: 'Smith'}) 

console.log(await userRepository.find()) //No results

json supprot

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/typeorm-encrypted/src/transformer.ts b/node_modules/typeorm-encrypted/src/transformer.ts
index ec5d1c8..f4e4d63 100644
--- a/node_modules/typeorm-encrypted/src/transformer.ts
+++ b/node_modules/typeorm-encrypted/src/transformer.ts
@@ -5,7 +5,7 @@ import { decryptData, encryptData } from './crypto';
 export class EncryptionTransformer implements ValueTransformer {
   constructor(private options: EncryptionOptions) {}
 
-  public from(value?: string | null): string | undefined {
+  public from(value?: string | null | object): string | undefined {
     if (!value) {
       return;
     }
@@ -55,3 +55,60 @@ export class EncryptionTransformer implements ValueTransformer {
     }
   }
 }
+export class JSONEncryptionTransformer implements ValueTransformer {
+  constructor(private options: EncryptionOptions) {}
+
+  public from(value?: string | null | object): string | undefined {
+    if (!value) {
+      return;
+    }
+
+    const decrypted = decryptData(
+      Buffer.from(value as string, 'base64'),
+      this.options
+    ).toString('utf8');
+
+    return JSON.parse(decrypted);
+  }
+
+  public to(value?: any | FindOperator<any> | null): string | FindOperator<any> | undefined{
+    if ((value ?? null) === null) {
+      return;
+    }
+
+    if (typeof value === 'object' && !value.type) {
+      return encryptData(
+        Buffer.from(JSON.stringify(value) as string, 'utf8'),
+        this.options
+      ).toString('base64');
+    }
+
+    if (!value) {
+      return;
+    }
+    // Support FindOperator.
+    // Just support "Equal", "In", "Not", and "IsNull".
+    // Other operators aren't work correctly, because values are encrypted on the db.
+    if (value.type === `in`) {
+      return In((value.value as string[]).map(s =>
+        encryptData(
+          Buffer.from(s, 'utf-8'),
+          this.options
+        ).toString('base64')
+      ));
+    } else if (value.type === 'equal') {
+      return Equal(encryptData(
+        Buffer.from(value.value as string, 'utf-8'),
+        this.options
+      ).toString('base64'));
+    } else if (value.type === 'not') {
+      return Not(
+        this.to(value.child ?? value.value)
+      );
+    } else if (value.type === 'isNull') {
+      return value
+    } else {
+      throw new Error('Only "Equal","In", "Not", and "IsNull" are supported for FindOperator');
+    }
+  }
+}

This issue body was partially generated by patch-package.

Cannot find module

I currently have a problem when I run the npm run start, I'm not quite sure if it's a problem with the typescript setting

error TS2307: Cannot find module 'typeorm-encrypted' or its corresponding type declarations.

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  }
}                                            

not works with aes-256-gcm

Hello,

I do :

export const MyEncryptionTransformerConfig = {
    key: 'e41c966f21f9e1577802463f8924e6a3fe3e9751f201304213b2f845d8841d61',
    algorithm: 'aes-256-gcm',
    ivLength: 16,
};

It encrypt but when I would display if failed.....
Error : Unsupported state or unable to authenticate data

Thanks

Doesnt work inside QueryBuilder

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;

Exception occurres when use FindOperator.

To use 'where in' clause, I execute next code. But TypeError is thrown.
Are there any way to avoid this?

import { In } from "typeorm"

const repo = getRepository<XXX>()

await repo.find({
  where: {
    encryptedField: In(["aaa"])
  }
})

Error

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of FindOperator

      at EncryptionTransformer.Object.<anonymous>.EncryptionTransformer.to (node_modules/typeorm-encrypted/src/transformer.ts:28:4)
      at Function.Object.<anonymous>.ApplyValueTransformers.transformTo (src/util/ApplyValueTransformers.ts:19:28)
      at ColumnMetadata.Object.<anonymous>.ColumnMetadata.getEntityValue (src/metadata/ColumnMetadata.ts:658:44)
      at SelectQueryBuilder.<anonymous> (src/query-builder/QueryBuilder.ts:1088:51)
      at step (node_modules/typeorm/node_modules/tslib/tslib.js:143:27)
      at Object.next (node_modules/typeorm/node_modules/tslib/tslib.js:124:57)
      at SelectQueryBuilder.Object.<anonymous>.QueryBuilder.getWhereCondition (src/query-builder/QueryBuilder.ts:1208:80)
      at SelectQueryBuilder.Object.<anonymous>.SelectQueryBuilder.where (src/query-builder/SelectQueryBuilder.ts:721:32)

generate key "Invalid key length"

Hello,

When I generate key I see error : "Invalid key length"

I do for exemple :

export const MyEncryptionTransformerConfig = {
    key: Buffer.from(env.app.crypto.key, 'utf8').toString('base64'),
    algorithm: env.app.crypto.algorithm,
    ivLength: 16,
};

In env I add :
env.app.crypto.key = nCM*R$izc*G3vqg7jo086mbc9Rg^7NYl

Thanks

bug

The example in readme for transformers doesnot work. getting invalid iv length

Use embedded entities to define instead of a decorator

typeorm has embedded entities (http://typeorm.io/#/embedded-entities) which allows for custom type definitions. If listeners can operate on embedded entities, this would negate the need for decorators and complicated field search code.

Example defintion:

import { Column, AfterLoad, BeforeInsert, BeforeUpdate } from "typeorm";

import { encryptData, decryptData } from "../transformers";
import { IEncryptedEntityOptions } from "./IEncryptedEntityOptions";

export class EncryptedEntity {
  options: IEncryptedEntityOptions;

  @Column({
    type: "varchar",
    nullable: false
  })
  data: string;

  EncryptedEntity(options: IEncryptedEntityOptions) {
    this.options = options;
  }

  @AfterLoad()
  decryptFields(): void {
    if (this.options.autoencrypt) {
      this.data = decryptData(this.data);
    }
  }

  @BeforeInsert()
  encryptFieldsBeforeInsert(): void {
    if (this.options.autoencrypt) {
      this.data = encryptData(this.data);
    }
  }

  @BeforeUpdate()
  encryptFieldsBeforeUpdate(): Promise<this> {
    if (this.options.autoencrypt) {
      this.data = encryptData(this.data);
    }
  }
}

It doesn't encrypt the default value of the column

When you specify column like this:

@Column({
    default: 'TEST_DATA',
    transformer: new EncryptionTransformer({
      key: '<key>',
      algorithm: 'aes-128-cbc',
      ivLength: 16,
    }),
  })
  encryptedColumn: string;

It inserts exact value that is specified in the default field instead of encrypted one.

I'm testing it with autoLoadEntities === true

Can i do a filter operation or serch operation using this

Hello ,

i have database requirement is fully encrypted database to store i also requirement to filter all record so can it is possible to do a search operation with encrypted database using typeorm?

if it is really possible so give your throat how we have do it ?

Release current master

I just ran into a problem that I've spent a little while diagnosing. I've forked the repo and gone to make my edits for a PR and found that the current master branch contains the fix I need.

Any chance of getting the master branch published to npm?

Feedback on design

  • I would suggest you to avoid forcing users to extend EncryptedBaseEntity class if possible. Usually users don't like to extend third party classes or change their model inheritance tree. (just imagine if there is another libs who force to extend their entities too and user uses them all)
  • @EncryptedColumn looks fine, its not a valid from typeorm point of view because this decorator is not creating a new column (like all Column decorators in typeorm), it just makes it encrypted. I would name it simply @Encrypted instead.
  • Also, its no a suggestion, just a hint most users don't know. You can override ColumnOptions properties and do it alternatively this way (it will be type-safe):
@Column({
    type: "varchar",
    nullable: false,
    encrypt: {
        key: "d85117047fd06d3afa79b6e44ee3a52eb426fc24c3a2e3667732e8da0342b4da",
        algorithm: "aes-256-cbc",
        ivLength: 16
    }
  })

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.