Skip to content

Commit 6a28695

Browse files
committed
cleanup crypt
1 parent cba84f4 commit 6a28695

1 file changed

Lines changed: 3 additions & 51 deletions

File tree

OpenFlowNodeRED/src/nodeclient/Crypt.ts

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,12 @@ export class Crypt {
1212
static encryption_key(): string {
1313
return Config.aes_secret.substr(0, 32);
1414
}
15-
16-
static encrypt(text: string): string {
17-
let iv: Buffer = crypto.randomBytes(Crypt.iv_length);
18-
let cipher: crypto.Cipher = crypto.createCipheriv("aes-256-cbc", Buffer.from(Crypt.encryption_key()), iv);
19-
let encrypted: Buffer = cipher.update((text as any));
20-
encrypted = Buffer.concat([encrypted, cipher.final()]);
21-
return iv.toString("hex") + ":" + encrypted.toString("hex");
22-
}
23-
24-
static decrypt(text: string): string {
25-
let textParts: string[] = text.split(":");
26-
let iv: Buffer = Buffer.from(textParts.shift(), "hex");
27-
let encryptedText: Buffer = Buffer.from(textParts.join(":"), "hex");
28-
let decipher: crypto.Decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(Crypt.encryption_key()), iv);
29-
let decrypted: Buffer = decipher.update(encryptedText);
30-
decrypted = Buffer.concat([decrypted, decipher.final()]);
31-
return decrypted.toString();
32-
}
33-
34-
static async hash(password: string): Promise<string> {
35-
return new Promise<string>(async (resolve, reject) => {
36-
try {
37-
bcrypt.hash(password, Crypt.bcrypt_salt_rounds, async (error, hash) => {
38-
if (error) { return reject(error); }
39-
resolve(hash);
40-
});
41-
} catch (error) {
42-
reject(error);
43-
}
44-
});
45-
}
46-
47-
static async compare(password: string, passwordhash: string): Promise<boolean> {
48-
return new Promise<boolean>(async (resolve, reject) => {
49-
try {
50-
bcrypt.compare(password, passwordhash, async (error, res) => {
51-
if (error) { return reject(error); }
52-
resolve(res);
53-
});
54-
} catch (error) {
55-
reject(error);
56-
}
57-
});
58-
}
59-
15+
/**
16+
* @deprecated The method should not be used
17+
*/
6018
static createToken(user: TokenUser): string {
6119
const token: string = jsonwebtoken.sign({ data: user }, Crypt.encryption_key(),
6220
{ expiresIn: "1h" }); // 60 (seconds), "2 days", "10h", "7d"
6321
return token;
6422
}
65-
66-
static verityToken(token: string): TokenUser {
67-
const o: any = jsonwebtoken.verify(token, Crypt.encryption_key());
68-
o.data = TokenUser.assign(o.data);
69-
return o.data;
70-
}
7123
}

0 commit comments

Comments
 (0)