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

> Node-JS code to generate header: #179

Open
pawan2004may opened this issue Dec 28, 2021 · 0 comments · May be fixed by #185
Open

> Node-JS code to generate header: #179

pawan2004may opened this issue Dec 28, 2021 · 0 comments · May be fixed by #185

Comments

@pawan2004may
Copy link

Node-JS code to generate header:

You're using an external library. Why? Node has native libraries for this. And all this array magic can be abstracted away using Buffers:

function encrypt({password, publicKey, publicKeyId}) {
    const time = Date.now().toString();
    const key = crypto.pseudoRandomBytes(32);
    const iv = Buffer.alloc(12, 0);
    const cipher = crypto.createCipheriv('aes-256-gcm', key, iv).setAAD(Buffer.from(time));
    const aesEncrypted = Buffer.concat([cipher.update(Buffer.from(password)), cipher.final()]);
    const authTag = cipher.getAuthTag();
    const encryptedKey = seal(key, Buffer.from(publicKey, 'hex'));
    return {
      encrypted: Buffer.concat([
        Buffer.from([
          1,
          Number(publicKeyId),
          encryptedKey.byteLength & 255,
          (encryptedKey.byteLength >> 8) & 255,
        ]),
        encryptedKey,
        authTag,
        aesEncrypted,
      ]).toString('base64'),
      time,
    };
  }
function generateEncPassword({password, publicKey, publicKeyId, encryptionVersion}) {
  const  { encrypted, time } = encrypt({password, publicKey, publicKeyId});
  return `#PWD_INSTAGRAM_BROWSER:${encryptionVersion}:${time}:${encrypted}`;
}

seal() is a function from tweetnacl-sealed-box.

Originally posted by @Nerixyz in #140 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant