Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Adds support for JSON Encryption #45

Merged
merged 6 commits into from
May 27, 2022

Conversation

Theo-
Copy link
Contributor

@Theo- Theo- commented Dec 7, 2021

Adds support for a JSON column encryption. Does exactly the same thing as the string column encryption and works the same way.

Can be used in a similar way:

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

@Entity()
class User {
  ...

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

  ...
}

Details:
This will store the json value as { encrypted: '<encrypted jsonified string>' } and automatically transformed back to the origin json when read from the database.

@generalpiston
Copy link
Owner

generalpiston commented Dec 7, 2021

@Theo- thanks for putting this PR together.

I have a question: can we reuse the other transformer? We could pass an argument that tells the transformer to parse and stringify the object.

Usage might look like this:

@Column({
    type: "json",
    nullable: false,
    transformer: new EncryptionTransformer({
      key: 'e41c966f21f9e1577802463f8924e6a3fe3e9751f201304213b2f845d8841d61',
      algorithm: 'aes-256-cbc',
      ivLength: 16,
      iv: 'ff5ac19190424b1d88f9419ef949ae56',
      json: true
    })
  })
  secretObject: object;

Let me know if you have any questions or thoughts!

Copy link
Owner

@generalpiston generalpiston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this in since we seem to have people asking for it. We can adjust it later.

@generalpiston generalpiston merged commit 45558d1 into generalpiston:master May 27, 2022
This was referenced May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants