🛠 Ability to work without encryption in db (#33)

* Ability to work without encryption in db
This commit is contained in:
Romaric Mourgues
2023-04-24 21:37:09 +02:00
committed by GitHub
parent b6420f280c
commit c2ae23137b
2 changed files with 19 additions and 14 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"database": { "database": {
"secret": "ab63bb3e90c0271c9a1c06651a7c0967eab8851a7a897766", "secret": "",
"mongodb": { "mongodb": {
"uri": "mongodb://mongo:27017" "uri": "mongodb://mongo:27017"
}, },
+18 -13
View File
@@ -19,22 +19,26 @@ export type CryptoResult = {
}; };
export function decrypt(data: string, encryptionKey: string): CryptoResult { export function decrypt(data: string, encryptionKey: string): CryptoResult {
let result = v2.decrypt(data, encryptionKey); if (encryptionKey) {
if (result.done) { let result = v2.decrypt(data, encryptionKey);
if (result.done) {
return result;
}
result = v1.decrypt(data, encryptionKey);
if (result.done) {
return result;
}
result = legacy.decrypt(data, encryptionKey);
if (result.done) {
return result;
}
return result; return result;
} }
result = v1.decrypt(data, encryptionKey); return { data, done: true };
if (result.done) {
return result;
}
result = legacy.decrypt(data, encryptionKey);
if (result.done) {
return result;
}
return result;
} }
export function md5(value: string): string { export function md5(value: string): string {
@@ -46,5 +50,6 @@ export function encrypt(
encryptionKey: any, encryptionKey: any,
options: { disableSalts?: boolean } = {}, options: { disableSalts?: boolean } = {},
): CryptoResult { ): CryptoResult {
if (!encryptionKey) return { data: `${value}`, done: true };
return v2.encrypt(value, encryptionKey, options); return v2.encrypt(value, encryptionKey, options);
} }