Skip to content

Commit 91042e7

Browse files
committed
transition to GCM
1 parent 6a28695 commit 91042e7

5 files changed

Lines changed: 25 additions & 11 deletions

File tree

OpenFlow/src/Crypt.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class Crypt {
4444
}
4545
static encrypt(text: string): string {
4646
let iv: Buffer = crypto.randomBytes(Crypt.iv_length);
47-
let cipher: crypto.Cipher = crypto.createCipheriv("aes-256-cbc", Buffer.from(Crypt.encryption_key), iv);
47+
let cipher: crypto.Cipher = crypto.createCipheriv("AES-256-GCM", Buffer.from(Crypt.encryption_key), iv);
4848
let encrypted: Buffer = cipher.update((text as any));
4949
encrypted = Buffer.concat([encrypted, cipher.final()]);
5050
return iv.toString("hex") + ":" + encrypted.toString("hex");
@@ -53,9 +53,16 @@ export class Crypt {
5353
let textParts: string[] = text.split(":");
5454
let iv: Buffer = Buffer.from(textParts.shift(), "hex");
5555
let encryptedText: Buffer = Buffer.from(textParts.join(":"), "hex");
56-
let decipher: crypto.Decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(Crypt.encryption_key), iv);
57-
let decrypted: Buffer = decipher.update(encryptedText);
58-
decrypted = Buffer.concat([decrypted, decipher.final()]);
56+
let decrypted: Buffer
57+
try {
58+
let decipher: crypto.Decipher = crypto.createDecipheriv("AES-256-GCM", Buffer.from(this.encryption_key), iv);
59+
decrypted = decipher.update(encryptedText);
60+
decrypted = Buffer.concat([decrypted, decipher.final()]);
61+
} catch {
62+
let decipher: crypto.Decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(this.encryption_key), iv);
63+
decrypted = decipher.update(encryptedText);
64+
decrypted = Buffer.concat([decrypted, decipher.final()]);
65+
}
5966
return decrypted.toString();
6067
}
6168
static async hash(password: string): Promise<string> {

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.3.11",
3+
"version": "1.3.12",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

OpenFlowNodeRED/src/node-red-contrib-openflow-storage.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class noderedcontribopenflowstorage {
7171
static encrypt(text: string): string {
7272
try {
7373
let iv: Buffer = crypto.randomBytes(this.iv_length);
74-
let cipher: crypto.Cipher = crypto.createCipheriv("aes-256-cbc", Buffer.from(this.encryption_key), iv);
74+
let cipher: crypto.Cipher = crypto.createCipheriv("AES-256-GCM", Buffer.from(this.encryption_key), iv);
7575
let encrypted: Buffer = cipher.update((text as any));
7676
encrypted = Buffer.concat([encrypted, cipher.final()]);
7777
return iv.toString("hex") + ":" + encrypted.toString("hex");
@@ -85,9 +85,16 @@ export class noderedcontribopenflowstorage {
8585
let textParts: string[] = text.split(":");
8686
let iv: Buffer = Buffer.from(textParts.shift(), "hex");
8787
let encryptedText: Buffer = Buffer.from(textParts.join(":"), "hex");
88-
let decipher: crypto.Decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(this.encryption_key), iv);
89-
let decrypted: Buffer = decipher.update(encryptedText);
90-
decrypted = Buffer.concat([decrypted, decipher.final()]);
88+
let decrypted: Buffer
89+
try {
90+
let decipher: crypto.Decipher = crypto.createDecipheriv("AES-256-GCM", Buffer.from(this.encryption_key), iv);
91+
decrypted = decipher.update(encryptedText);
92+
decrypted = Buffer.concat([decrypted, decipher.final()]);
93+
} catch {
94+
let decipher: crypto.Decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(this.encryption_key), iv);
95+
decrypted = decipher.update(encryptedText);
96+
decrypted = Buffer.concat([decrypted, decipher.final()]);
97+
}
9198
return decrypted.toString();
9299
} catch (error) {
93100
console.error(error);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.11
1+
1.3.12

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.3.11",
3+
"version": "1.3.12",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)