3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-12 21:05:02 +00:00

Encrypt message data at rest

This commit is contained in:
Dragory 2020-09-16 22:32:43 +03:00
parent 3f3d6af4ed
commit baa3a5640e
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
10 changed files with 121 additions and 3 deletions

View file

@ -0,0 +1,22 @@
import { decrypt, encrypt } from "../utils/crypt";
import { ValueTransformer } from "typeorm";
interface EncryptedJsonTransformer<T> extends ValueTransformer {
from(dbValue: any): T;
to(entityValue: T): any;
}
export function createEncryptedJsonTransformer<T>(): EncryptedJsonTransformer<T> {
return {
// Database -> Entity
from(dbValue) {
const decrypted = decrypt(dbValue);
return JSON.parse(decrypted) as T;
},
// Entity -> Database
to(entityValue) {
return encrypt(JSON.stringify(entityValue));
},
};
}