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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sign-encrypt

v1.0.2

Published

A utility for generating encrypted signatures with multiple algorithms support

Readme

sign-encrypt

一个用于生成加密签名的工具库,支持多种加密算法和缓存机制。

特性

  • 默认使用 MD5 加密算法,支持 SHA256 和 SHA512
  • 内置缓存机制,提高性能
  • 完整的 TypeScript 类型支持
  • 支持签名验证
  • 支持对象过滤和嵌套对象处理
  • 支持调试模式,方便排查问题
  • 支持 ESM 和 CommonJS 模块系统

安装

npm install sign-encrypt

使用方法

ESM 导入

import { signEncrypt, verifySignature } from 'sign-encrypt';

CommonJS 导入

const { signEncrypt, verifySignature } = require('sign-encrypt');

基本使用

import { signEncrypt, verifySignature } from 'sign-encrypt';

const data = { name: 'test', age: 25 };
const signKey = 'your-secret-key';

// 生成签名(默认使用 MD5)
const signature = signEncrypt(data, signKey);

// 验证签名
const isValid = verifySignature(data, signature, signKey);

高级选项

import { signEncrypt } from 'sign-encrypt';

const data = { name: 'test', age: 25 };
const signKey = 'your-secret-key';

// 使用 SHA256 算法
const signature = signEncrypt(data, signKey, {
  algorithm: 'SHA256',
  enabled: true, // 启用缓存
  ttl: 3600000, // 缓存1小时
  debug: true, // 启用调试模式,打印签名参数信息
});

调试模式

启用调试模式后,会以表格形式打印以下信息:

  • 排序后的键
  • 过滤后的数据
  • 签名字符串
  • 签名密钥
  • 加密算法
  • 最终加密字符串
const signature = signEncrypt(data, signKey, {
  debug: true
});

// 输出示例:
// ┌───────────────┬─────────────────────────────┐
// │     (index)   │            Values           │
// ├───────────────┼─────────────────────────────┤
// │  排序后的键   │      ['age', 'name']        │
// │ 过滤后的数据  │ { age: 25, name: 'test' }   │
// │  签名字符串   │         '25||test'          │
// │  签名密钥     │      'your-secret-key'      │
// │  加密算法     │           'MD5'             │
// │最终加密字符串 │ '25||test||your-secret-key' │
// └───────────────┴─────────────────────────────┘

对象过滤

import { filterObjectByValue } from 'sign-encrypt';

const data = {
  name: 'test',
  age: 25,
  empty: '',
  null: null,
  nested: {
    value: 'test',
    empty: ''
  }
};

// 过滤空值
const filtered = filterObjectByValue(data, {
  keepEmptyString: false,
  recursive: true
});

API 文档

signEncrypt(data: object, signKey: string, options?: SignEncryptOptions): string

生成加密签名。

参数:

  • data: 要签名的数据对象
  • signKey: 签名密钥
  • options: 可选配置
    • algorithm: 加密算法 ('MD5' | 'SHA256' | 'SHA512'),默认为 'MD5'
    • enabled: 是否启用缓存
    • ttl: 缓存时间(毫秒)
    • debug: 是否启用调试模式,默认为 false

verifySignature(data: object, signature: string, signKey: string, options?: SignEncryptOptions): boolean

验证签名是否有效。

filterObjectByValue(obj: object, options?: SignEncryptOptions): object

过滤对象中的空值。

开发

# 安装依赖
npm install

# 运行测试
npm test

# 构建(同时生成 ESM 和 CommonJS 格式)
npm run build

# 生成文档
npm run docs

贡献

欢迎提交 Issue 和 Pull Request!

许可证

MIT