encrypt-stack
Version:
An encryption driver/stack to create a multi-layer encrypted workflow in Node.
32 lines (26 loc) • 780 B
JavaScript
'use strict';
const crypto = require("crypto");
const encrypt = require("./functions/encrypt.js");
const decrypt = require("./functions/decrypt.js");
const hash = require("./functions/hash.js");
class EncryptionDriver{
constructor(method, key_sync){
this.method = method || "bf-cbc";
this.key_sync = key_sync || "secp521r1";
this.crypto = crypto.createECDH(this.key_sync);
this.public_key = this.crypto.generateKeys("hex");
}
computeSecret(pubkey){
this.secret = this.crypto.computeSecret(pubkey, "hex", "hex");
}
encrypt(data){
return encrypt(this.method, this.secret, data);
}
decrypt(data){
return decrypt(this.method, this.secret, data);
}
hash(data){
return hash(data);
}
}
module.exports = EncryptionDriver;