npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mega-apps/node-ex

v1.0.0-alpha.15

Published

Mega-Apps node addon.

Downloads

20

Readme

@mega-apps/node-ex

Mega-Apps Node原生扩展模块 (采用 Rust 语言编写扩展)

1. API

1.1. Hash 计算

1.1.1. 获得代码的Hash值

1.1.1.1. 接口函数说明
/**
  * @param {Buffer} code 代码
  * @param {string} digest Hash 算法, 支持 md5, sha1, sha256, sha512,更多请参照:`openssl dgst -list`
  * 常用的 Hash 算法有:
    blake2b512                blake2s256                md4
    md5                       md5-sha1                  mdc2
    ripemd                    ripemd160                 rmd160
    sha1                      sha224                    sha256
    sha3-224                  sha3-256                  sha3-384
    sha3-512                  sha384                    sha512
    sha512-224                sha512-256                shake128
    shake256                  sm3                       ssl3-md5
    ssl3-sha1                 whirlpool
  * @return {Buffer} Hash值
  */
function get_code_hash(code, digest){}
1.1.1.2. 代码示例
const native = require('@mega-apps/node-ex');
const hash = native.get_code_hash(Buffer.from('Hello, world!'),'sha256');
console.log(hash.toString()); // 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3

1.1.2. 获得文件的Hash值

1.1.2.1. 接口函数说明
/**
  * @param {string} filePath 文件路径
  * @param {string} digest Hash 算法, 支持 md5, sha1, sha256, sha512,更多请参照:`openssl dgst -list`
  * 常用的 Hash 算法有:
    blake2b512                blake2s256                md4
    md5                       md5-sha1                  mdc2
    ripemd                    ripemd160                 rmd160
    sha1                      sha224                    sha256
    sha3-224                  sha3-256                  sha3-384
    sha3-512                  sha384                    sha512
    sha512-224                sha512-256                shake128
    shake256                  sm3                       ssl3-md5
    ssl3-sha1                 whirlpool
  * @return {Buffer} Hash值
  */
function get_code_file_hash(filePath, digest){}
1.1.2.2. 代码示例
const native = require('@mega-apps/node-ex');
const hash = native.get_code_file_hash('/path/to/file','sha256');

1.2. 生成密钥

1.2.1. 生成非对称密钥对(RSA)

1.2.1.1. 接口函数说明
/**
  * @param {Object} options 选项
  * - @param {string} options.passphrase 密码,默认空
  * - @param {string} options.pk_name 公钥文件路径,默认 rsa_public.pem
  * - @param {string} options.sk_name 私钥文件路径,默认 rsa_private.pem
  * @return {Object} {pk:Buffer, sk:Buffer}密钥对数据
  *  - @param {Buffer} pk 公钥
  *  - @param {Buffer} sk 私钥
  */
function generate_rsa_key_pair(optioins = {
  passphrase: '',
  pk_name: './key_public.pem',
  sk_name: './key_private.pem'
}){}
1.2.1.2. 代码示例

// 默认生成密钥对,并保存在当前目录下,密码为空,公钥文件名为 key_public.pem,私钥文件名为 key_private.pem
const native = require('@mega-apps/node-ex');
const {pk, sk} = native.generate_rsa_key_pair();

// 生成密钥对, 并保存到文件,密码为 123456,公钥文件名为 key_public.pem,私钥文件名为 key_private.pem
const native = require('@mega-apps/node-ex');
const {pk, sk} = native.generate_rsa_key_pair({
  passphrase: '123456',
  pk_name: './key_public.pem',
  sk_name: './key_private.pem'
});

1.2.2. 生成对称密钥(AES)

1.2.2.1. 接口函数说明
/**
  * @param {Object} options 选项
  * @param {string} options.file_name 密钥输出的文件的路径,默认为空字符串,不输出内容到文件
  * @return {Buffer} 密钥Buffer 数据
  */
function generate_aes_key(optioins = {
  file_name: '/path/to/file'
}){}
1.2.2.2. 代码示例
const native = require('@mega-apps/node-ex');
const key = native.generate_aes_key();

1.3. 使用非对称密钥加密/解密

1.3.1. 接口函数说明

/**
  * @param {Buffer} data 要加密的数据
  * @param {string/Buffer} key 加密密钥; string 类型为文件的路径; Buffer 类型为密钥buf数据
  * @param {Object} options 选项
  * - @param {string} options.passphrase 密码,默认空
  * @return {Buffer} 加密后的数据
  */
function encrypt_key_with_buffer(data, key_data, options= {}){}

/**
  * @param {string} file 要加密的文件的路径
  * @param {string/Buffer} key 加密密钥; string 类型为文件的路径; Buffer 类型为密钥buf数据
  * @param {string} output  输出加密后的文件的路径,为空字符串时,不输出到文件
  * @param {Object} options 选项
  * - @param {string} options.passphrase 密码,默认空
  * @return {Buffer} 加密后的数据
  */
function encrypt_key_with_file(file, key, output, options= {}){}

/**
  * @param {Buffer} data 要解密的数据
  * @param {string/Buffer} key 解密密钥; string 类型为文件的路径; Buffer 类型为密钥buf数据
  * @param {Object} options 选项
  * - @param {string} options.passphrase 密码,默认空
  * @return {Buffer} 解密后的数据
  */
function decrypt_key_with_buffer(data, key_data, options= {}){}

/**
  * @param {string} file 要解密的文件的路径
  * @param {string/Buffer} key  解密密钥; string 类型为文件的路径; Buffer 类型为密钥buf数据
  * @param {string} output  输出解密后的文件的路径,为空字符串时,不输出到文件
  * @param {Object} options 选项
  * - @param {string} options.passphrase 密码,默认空
  * @return {Buffer} 解密后的数据
  */
function decrypt_key_with_file(file, key, output, options= {}){}

1.3.2. 代码示例

const native = require('@mega-apps/node-ex');
const plainText = `sunzhifeng <[email protected]>`;

const pub_key = join(__dirname,'../../','./certs/rsa_public.pem');
const pri_key = join(__dirname,'../../','./certs/rsa_private.pem');

// 加密
const cipher = native.encrypt_key_with_buffer(Buffer.from(plainText),pub_key);
native.encrypt_key_with_file('/path/a.txt',pub_key, '/path/a.txt.enc');

// 解密
native.decrypt_key_with_buffer(cipher, pri_key);
native.decrypt_key_with_file('/path/a.txt.enc', pri_key, '/path/a.txt.dec');

1.4. 使用对称密钥加密/解密

1.4.1. 接口函数说明

/**
  * 对称加密
  * @param {Buffer} data 要加密的数据
  * @param {string/Buffer} key 加密密钥; string 类型为文件的路径; Buffer 类型为密钥buf数据
 * * @param {Object} options 选项
  * - @param {string} options.passphrase 密码,默认空
  * @return {Buffer} 加密后的数据
  */
function code_encrypt_with_buffer(data, key_data, options= {}){}

/**
  * 对称解密
  * @param {Buffer} data 要解密的数据
  * @param {string/Buffer} key 解密密钥; string 类型为文件的路径; Buffer 类型为密钥buf数据
  * @param {Object} options 选项
  * - @param {string} options.passphrase 密码,默认空
  * @return {Buffer} 加密后的数据
  */
function code_decrypt_with_buffer(data, key_data, options= {}){}
1.4.1.1. 代码示例
const native = require('@mega-apps/node-ex');

// 原文
const plain_buf = fs.readFileSync(join(rootDir,'./tests/fixtures/app.js'));
// 对称密钥
const key_buf = Buffer.from("DKA4EPOBOHnj8l0sS9hAbwGqZfH8VU9i^^");

const cipher_buf = native.code_encrypt_with_buffer(plain_buf,key_buf);
// fs.writeFileSync(join(rootDir,'./tests/fixtures/app.vue.cipher'),cipher_buf);
const plain_buf2 = native.code_decrypt_with_buffer(cipher_buf,key_buf);
// fs.writeFileSync(join(rootDir,'./tests/fixtures/app.vue.txt'),plain_buf2);

1.5. 数字签名及校验

1.5.1. 生成数字签名

1.5.1.1. 接口函数说明
/**
  * 生成数字签名
  * @param {Buffer} data 要签名的数据
  * @param {Buffer} key 签名密钥Buffer 数据
  * @param {string} digest Hash 算法, 支持 md5, sha1, sha256, sha512,更多请参照:`openssl dgst -list`
  * 常用的 Hash 算法有:
    blake2b512                blake2s256                md4
    md5                       md5-sha1                  mdc2
    ripemd                    ripemd160                 rmd160
    sha1                      sha224                    sha256
    sha3-224                  sha3-256                  sha3-384
    sha3-512                  sha384                    sha512
    sha512-224                sha512-256                shake128
    shake256                  sm3                       ssl3-md5
    ssl3-sha1                 whirlpool
  * @param {Object} options 选项
  * @return {Buffer} 签名后的数据
  */
function sign(data, key, digest, options= {}){}
1.5.1.2. 代码示例
const native = require('@mega-apps/node-ex');
const plainText = `sunzhifeng <[email protected]>`;

// 原文
const plain_buf = Buffer.from(plainText);
// 私钥
const key_buf = fs.readFileSync(join(rootDir,'./certs/key_private.pem'));
// 签名算法
const sign_algorithm = 'sha256';
// 调用签名方法
const sign_buf = native.sign(plain_buf,key_buf,sign_algorithm);

1.5.2. 校验数字签名

1.5.2.1. 接口函数说明
/**
  * 校验数字签名
  * @param {Buffer} data 要校验的数据
  * @param {Buffer} key 签名密钥Buffer 数据
  * @param {Buffer} signature 签名Buffer 数据
  * @param {string} digest Hash 算法, 支持 md5, sha1, sha256, sha512,更多请参照:`openssl dgst -list`
  * 常用的 Hash 算法有:
    blake2b512                blake2s256                md4
    md5                       md5-sha1                  mdc2
    ripemd                    ripemd160                 rmd160
    sha1                      sha224                    sha256
    sha3-224                  sha3-256                  sha3-384
    sha3-512                  sha384                    sha512
    sha512-224                sha512-256                shake128
    shake256                  sm3                       ssl3-md5
    ssl3-sha1                 whirlpool
  * @param {Object} options 选项
  * @return {boolean} 校验结果
  */
function verify(data, key, signature, digest, options= {}){} 
1.5.2.2. 代码示例
const native = require('@mega-apps/node-ex');
const plainText = `sunzhifeng <[email protected]>`;

// 原文
const plain_buf = Buffer.from(plainText);
// 私钥
const skey_buf = fs.readFileSync(join(rootDir,'./certs/key_private.pem'));
// 签名算法
const sign_algorithm = 'sha256';
// 调用签名方法
const sign_buf = native.sign(plain_buf,skey_buf,sign_algorithm);

// 公钥
const pkey_buf = fs.readFileSync(join(rootDir,'./certs/key_public.pem'));
// 验签算法
const verify_algorithm = 'sha256';
// 调用验签方法
const verify_result = native.verify(plain_buf,pkey_buf,sign_buf,verify_algorithm);