🚀 @mgcloud/uncrypto
这个库提供了一个统一的 API 来使用 Web Crypto 和 Subtle Crypto,支持在 Node.js 环境中使用 Crypto 模块 和在 Web 环境中使用 Web Crypto API,通过 条件导出 实现跨平台兼容。
系统要求
- Node.js: 版本 15 及以上 (本库不为旧版本提供任何 polyfill!)
- 浏览器: 需要 安全上下文 (HTTPS/Localhost) 且为 受支持的浏览器
- 其他运行时: 需要暴露
globalThis.crypto和globalThis.crypto.subtle。(如需要可自行添加 polyfill)
使用方法
安装包:
bash
# pnpm
pnpm install @mgcloud/uncrypto导入使用:
js
// ESM 模块
import { subtle, randomUUID, getRandomValues } from '@mgcloud/uncrypto'
// CommonJS 模块
const { subtle, randomUUID, getRandomValues } = require('@mgcloud/uncrypto')