nos2x icon indicating copy to clipboard operation
nos2x copied to clipboard

Support for master password

Open Anderson-Juhasc opened this issue 1 year ago • 5 comments

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 };
    }
  },

Anderson-Juhasc avatar Mar 30 '23 16:03 Anderson-Juhasc

This is a good idea.

fiatjaf avatar Mar 30 '23 16:03 fiatjaf

@Anderson-Juhasc did you code it yet? Send a PR :)

githubbbie avatar Jun 06 '23 03:06 githubbbie

@Anderson-Juhasc Love this! Hope to see a PR

amunrarara avatar Mar 29 '24 01:03 amunrarara

We'll implement NIP-49 eventually.

fiatjaf avatar Mar 29 '24 11:03 fiatjaf

@fiatjaf how could I implement this nip? Have any script ready?

Anderson-Juhasc avatar Mar 30 '24 21:03 Anderson-Juhasc