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

jssm4

v2.0.0

Published

国密SM4加解密工具,支持浏览器与Node环境

Readme

JSSM4

国密 SM4 加解密 JavaScript 实现,支持浏览器与 Node.js 环境。

特性

  • 高性能:基于 Uint32Array 和位运算优化,100万次加密仅需 ~1.5s
  • 现代化:使用 ES6+ 语法,支持 TextEncoder/TextDecoder 原生编解码
  • 模式支持:完整支持 ECBCBC 加解密模式
  • 零依赖:除必要的 base64-js 外无其他外部依赖
  • 跨平台:支持 ESM、CommonJS、UMD 多种模块格式,包含 TypeScript 类型定义

性能 (Node.js 20 + M3 Pro)

100万次加解密耗时 (3字符明文):

加密100w耗时: ~1.5s
解密100w耗时: ~1.8s

安装

npm install jssm4

使用

ECB 模式

import JSSM4 from 'jssm4';

const sKey = "qawsedrftgyhujik"; // 16字节密钥
const sm4 = new JSSM4(sKey);

// 加密
const encrypted = sm4.encryptData_ECB("Hello SM4");
console.log(encrypted);

// 解密
const decrypted = sm4.decryptData_ECB(encrypted);
console.log(decrypted); // Hello SM4

CBC 模式

import JSSM4 from 'jssm4';

const sKey = "qawsedrftgyhujik"; // 16字节密钥
const sIv = "1234567890123456";  // 16字节向量
const sm4 = new JSSM4(sKey);

// 加密
const encrypted = sm4.encryptData_CBC("Hello CBC", sIv);

// 解密
const decrypted = sm4.decryptData_CBC(encrypted, sIv);
console.log(decrypted); // Hello CBC

API

new JSSM4(key: string)

创建 SM4 实例

  • key: 16 字符长度的密钥字符串(UTF-8 编码应为 16 字节)

encryptData_ECB(plainText: string): string

decryptData_ECB(cipherText: string): string

ECB 模式加解密

encryptData_CBC(plainText: string, iv: string): string

decryptData_CBC(cipherText: string, iv: string): string

CBC 模式加解密

  • iv: 16 字符长度的初始化向量字符串

开发

# 安装依赖
npm install

# 构建
npm run build

# 测试
npm test

环境要求

  • Node.js: >= 20.0.0 (利用 TextEncoder 和现代位运算优化)
  • Browser: 现代浏览器 (支持 Uint32ArrayTextEncoder)

构建输出

| 格式 | 文件 | 用途 | |------|------|------| | ESM | lib/jssm4.esm.js | 现代打包工具(Vite、Webpack 等) | | CommonJS | lib/jssm4.cjs.js | Node.js require() | | UMD | lib/jssm4.js | 浏览器 <script> 标签 |


基于 泪血夕阳 sm4实现博文 参考 windard 循环左移实现