Skip to content

is there any nodejs equivalent implementation? #30

@xiangnanscu

Description

@xiangnanscu

ngx_encrypted_session will plant an expiration time this part is hard. I don't know how to implement it in nodejs. I try to use this snippet to decrypt the string encrypted by encrypted-session-nginx-module, the output is a partial success:

>82^��/H�����j�EG��ɭ���tޡ�楠","permission":128,"username":"11111111","id":1}}c@9}

the nodejs decrypt snippet

import crypto from "crypto";

const ENC_KEY = "xxxxxxxx"; // set random encryption key
const IV = "xxxxxxx"; // set random initialisation vector
// ENC_KEY and IV can be generated as crypto.randomBytes(32).toString('hex');

// const phrase = "who let the dogs out";

const encrypt = (val: string) => {
  let cipher = crypto.createCipheriv("aes-256-cbc", ENC_KEY, IV);
  let encrypted = cipher.update(val, "utf8", "base64");
  encrypted += cipher.final("base64");
  return encrypted;
};

const decrypt = (encrypted: string) => {
  let decipher = crypto.createDecipheriv("aes-256-cbc", ENC_KEY, IV);
  let decrypted = decipher.update(encrypted, "base64", "utf8");
  return decrypted + decipher.final("utf8");
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions