{"id":19610514,"url":"https://github.com/originjs/crypto-js-wasm","last_synced_at":"2025-04-04T16:17:19.241Z","repository":{"id":44339811,"uuid":"461078535","full_name":"originjs/crypto-js-wasm","owner":"originjs","description":"An alternative to crypto-js implemented with WebAssembly and ESM","archived":false,"fork":false,"pushed_at":"2024-07-11T09:44:45.000Z","size":8115,"stargazers_count":236,"open_issues_count":8,"forks_count":21,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T06:35:27.146Z","etag":null,"topics":["crypto","crypto-js","rsa"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/originjs.png","metadata":{"files":{"readme":"README-CN.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-19T03:46:41.000Z","updated_at":"2025-03-22T10:58:45.000Z","dependencies_parsed_at":"2024-10-12T00:16:21.088Z","dependency_job_id":null,"html_url":"https://github.com/originjs/crypto-js-wasm","commit_stats":{"total_commits":235,"total_committers":31,"mean_commits":7.580645161290323,"dds":0.625531914893617,"last_synced_commit":"c018d05c60f6fd6021c952efcae6c640cd026fc1"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originjs%2Fcrypto-js-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originjs%2Fcrypto-js-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originjs%2Fcrypto-js-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originjs%2Fcrypto-js-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/originjs","download_url":"https://codeload.github.com/originjs/crypto-js-wasm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208190,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crypto","crypto-js","rsa"],"created_at":"2024-11-11T10:29:48.185Z","updated_at":"2025-04-04T16:17:19.217Z","avatar_url":"https://github.com/originjs.png","language":"JavaScript","funding_links":[],"categories":["Projects"],"sub_categories":["Others"],"readme":"# @originjs/crypto-js-wasm\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/originjs/crypto-js-wasm/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://github.com/originjs/crypto-js-wasm/actions/workflows/ci.yml/badge.svg?branch=main\" alt=\"Build Status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@originjs/crypto-js-wasm\"\u003e\u003cimg src=\"https://badgen.net/npm/v/@originjs/crypto-js-wasm\" alt=\"Version\"\u003e\u003c/a\u003e\n \u003c/p\u003e\n\n[English](README.md) | [中文](README-CN.md)\n\n---\n\n`crypto-js-wasm` 是基于 JavaScript 和 [WebAssembly](https://webassembly.org/) 的哈希与加密算法库，其灵感来自于[crypto-js](https://github.com/brix/crypto-js)。\n\n- **安全**: 得益于 WebAssembly ，crypto-js-wasm的计算过程是**不可见、不可中断**的\n- **高效**: 相比于crypto-js，计算效率最高提升了16倍(见 [Benchmark](https://originjs.org/WASM-benchmark/#/))\n- **兼容crypto-js**: 与crypto-js的API完全相同\n- **浏览器 \u0026 Nodejs**: 同时支持 `浏览器` 和 `nodejs`\n- **全能**: 支持**15+** 以上的哈希和加密算法，包括常用的 MD5、 SHA-x、 AES、RC4等\n- **ESM**: 基于ESM语法编写，编译为UMD以保证兼容性\n\n\n\n## 最新消息\n\n当前已经支持RSA和TypeScript!\n\n\n\n## 安装\n\n```bash\nnpm install @originjs/crypto-js-wasm\n```\n\n或\n\n```bash\npnpm install @originjs/crypto-js-wasm\n```\n\n或\n\n```bash\nyarn add @originjs/crypto-js-wasm\n```\n\n\n\n## 使用\n\n在使用各算法前需调用一次对应的`loadWasm()`，或调用`loadAllWasm()`以加载所有算法的WebAssembly文件。\n\n```javascript\nimport CryptoJSW from '@originjs/crypto-js-wasm';\n\n// (可选) 加载所有 wasm 文件\nawait CryptoJSW.loadAllWasm();\n\n// 通过 Async/Await 语法调用\nawait CryptoJSW.MD5.loadWasm();\nconst rstMD5 = CryptoJSW.MD5('message').toString();\nconsole.log(rstMD5);\n\n// 通过 Promise 语法调用\nCryptoJSW.SHA256.loadWasm().then(() =\u003e {\n    const rstSHA256 = CryptoJSW.SHA256('message').toString();\n    console.log(rstSHA256);\n})\n```\n\n需要注意的是，`HMAC` 没有`loadWasm`，因为如果要使用`HMAC`，必须指定哈希（例如`HmacSHA1`）。\n\n同时， `pbkdf2` 中的 `loadWasm` 实现是调用了 `SHA1.loadWasm` ，这是因为 `SHA1` 是 `pbkdf2` 的默认哈希算法。 如果指定了另一个哈希算法，则应分别调用该哈希算法对应的 `loadWasm`。 `evpkdf`/`MD5` 的情况与之类似， `MD5` 是 `evpkdf` 的默认哈希算法。\n\n**RSA使用说明**\n\n请参考[这篇文档](./docs/rsa-CN.md).\n\n\n\n**目前可用的算法**\n\n- MD5 / HmacMD5\n- SHA1 / HmacSHA1\n- SHA224 / HmacSHA224\n- SHA256 / HmacSHA256\n- SHA384 / HmacSHA384\n- SHA512 / HmacSHA512\n- SHA3 / HmacSHA3\n- RIPEMD160 / HmacRIPEMD160\n- PBKDF2\n- EvpKDF\n\n\u003cbr\u003e\n\n- AES\n- Blowfish\n- DES\n- TripleDES\n- Rabbit\n- RabbitLegacy\n- RC4\n- RC4Drop\n\n- RSA\n\n\n\n## Benchmark\n\n以下 benchmark 结果运行自一台台式机 (i5-4590, 16 GB RAM, Windows 10 Version 21H2 (OSBuild 19044, 1466))。\n\n\n\n*Chrome 102.0.5005.63:*\n\n![benchmark_chrome](benchmark/benchmark_chrome.png)\n\n\n\n*Firefox 101.0:*\n\n![benchmark_firefox](benchmark/benchmark_firefox.png)\n\n\n\n*Nodejs v16.6.4:*\n\n![nodejs](benchmark/benchmark_nodejs.png)\n\n\n\n*RSA(vs jsencrypt) in Chrome:*\n\n![rsa_chrome](benchmark/benchmark_chrome_rsa.png)\n\n\n\n## 开发\n\n```bash\n# 安装依赖\npnpm install\n\n# 生产构建\npnpm run build\n\n# 运行所有测试\npnpm run test\n\n#  运行所有测试并生成测试覆盖率报告\npnpm run coverage\n```\n\n\n\n#### 为何我们需要调用异步的 loadWasm？\n\n这是因为 WebAssembly 二进制需要通过 `WebAssembly.instantiate` 加载，并且这是一个异步函数。\n\n`WebAssembly.instantiate `与它的同步实现 `WebAssembly.instance` 相比，前者更受推荐；并且，在许多场景下，`WebAssembly.instance` 无法加载不够小的 WebAssembly 二进制。\n\n\n\n#### 为何我们需要以base64编码字符的方式，存储wasm二进制？\n\n因为 `crypto-js-wasm` 需要同时支持 `browser` 和 `nodejs` 两种使用场景。相比与 `browser` 中的 `wasm loader` (多数情况下由 webpack, vite 或其他框架提供)以及 `nodejs` 中的 `fs` 方式，这种wasm二进制存储方式是一种相对优雅的方式。\n\n\n\n## 版权说明\n\n该项目遵守[木兰宽松许可证](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foriginjs%2Fcrypto-js-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foriginjs%2Fcrypto-js-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foriginjs%2Fcrypto-js-wasm/lists"}