nos2x
nos2x copied to clipboard
Support for master password
Something similar to Password Manager master password.
Code example:
encryptObject(obj, password) {
try {
const iv = crypto.randomBytes(16);
const salt = crypto.randomBytes(64);
const key = crypto.pbkdf2Sync(password, salt, 100000, 32, "sha512");
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
let encrypted = cipher.update(JSON.stringify(obj), "utf8", "hex");
encrypted += cipher.final("hex");
return {
iv: iv.toString("hex"),
encrypted: encrypted,
salt: salt.toString("hex"),
};
} catch (e) {
return { error: e.reason };
}
},
decryptObject(data, password) {
try {
const iv = Buffer.from(data.iv, "hex");
const salt = Buffer.from(data.salt, "hex");
const key = crypto.pbkdf2Sync(password, salt, 100000, 32, "sha512");
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
let decrypted = decipher.update(data.encrypted, "hex", "utf8");
decrypted += decipher.final("utf8");
return JSON.parse(decrypted);
} catch (e) {
return { error: e.reason };
}
},
This is a good idea.
@Anderson-Juhasc did you code it yet? Send a PR :)
@Anderson-Juhasc Love this! Hope to see a PR
We'll implement NIP-49 eventually.
@fiatjaf how could I implement this nip? Have any script ready?