Return to scrypt
This commit is contained in:
@@ -73,7 +73,7 @@ async function main() {
|
|||||||
class Encrypter {
|
class Encrypter {
|
||||||
static initialize(encryptionKey) {
|
static initialize(encryptionKey) {
|
||||||
console.log(`Initializing encrypter with key: ${encryptionKey}`);
|
console.log(`Initializing encrypter with key: ${encryptionKey}`);
|
||||||
this.key = encryptionKey;
|
this.key = crypto.scryptSync(encryptionKey, 'salt', 32);
|
||||||
}
|
}
|
||||||
static encrypt(clearText) {
|
static encrypt(clearText) {
|
||||||
const iv = crypto.randomBytes(16);
|
const iv = crypto.randomBytes(16);
|
||||||
@@ -92,7 +92,7 @@ class Encrypter {
|
|||||||
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
|
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
|
||||||
}
|
}
|
||||||
static hash(clearText) {
|
static hash(clearText) {
|
||||||
return crypto.createHmac('sha256', this.key).update(clearText).digest('base64');
|
return crypto.createHash('sha256', this.key).update(clearText).digest('base64');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Encrypter.algorithm = 'aes-256-cbc';
|
Encrypter.algorithm = 'aes-256-cbc';
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import crypto from 'crypto';
|
|||||||
|
|
||||||
export class Encrypter {
|
export class Encrypter {
|
||||||
private static algorithm = 'aes-256-cbc';
|
private static algorithm = 'aes-256-cbc';
|
||||||
private static key: string;
|
private static key: Buffer;
|
||||||
|
|
||||||
static initialize(encryptionKey: string) {
|
static initialize(encryptionKey: string) {
|
||||||
console.log(`Initializing encrypter with key: ${encryptionKey}`);
|
console.log(`Initializing encrypter with key: ${encryptionKey}`);
|
||||||
this.key = encryptionKey;
|
this.key = crypto.scryptSync(encryptionKey, 'salt', 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
static encrypt(clearText: string): string {
|
static encrypt(clearText: string): string {
|
||||||
@@ -38,6 +38,6 @@ export class Encrypter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static hash(clearText: string): string {
|
static hash(clearText: string): string {
|
||||||
return crypto.createHmac('sha256', this.key).update(clearText).digest('base64');
|
return crypto.createHash('sha256', this.key).update(clearText).digest('base64');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user