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:
parent
3f3d6af4ed
commit
baa3a5640e
10 changed files with 121 additions and 3 deletions
22
backend/src/data/encryptedJsonTransformer.ts
Normal file
22
backend/src/data/encryptedJsonTransformer.ts
Normal 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));
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue