Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for master password #36

Open
Anderson-Juhasc opened this issue Mar 30, 2023 · 5 comments
Open

Support for master password #36

Anderson-Juhasc opened this issue Mar 30, 2023 · 5 comments

Comments

@Anderson-Juhasc
Copy link
Contributor

Anderson-Juhasc commented Mar 30, 2023

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 };
    }
  },
@fiatjaf
Copy link
Owner

fiatjaf commented Mar 30, 2023

This is a good idea.

@githubbbie
Copy link

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

@amunrarara
Copy link

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

@fiatjaf
Copy link
Owner

fiatjaf commented Mar 29, 2024

We'll implement NIP-49 eventually.

@Anderson-Juhasc
Copy link
Contributor Author

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

@Anderson-Juhasc Anderson-Juhasc mentioned this issue Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants