{"_id":"@1-/hash","name":"@1-/hash","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@1-/hash","version":"0.1.0","description":"Length-bounded MD5 hash utility / 长度受限的 MD5 哈希工具","keywords":["crypto","hash","length-bounded","md5"],"homepage":"https://github.com/webc-site/npm/tree/main/hash","license":"MulanPSL-2.0","author":{"name":"x-at-01@googlegroups.com"},"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"type":"module","exports":{"./*":"./*"},"peerDependencies":{"@3-/utf8":"^0.1.1"},"_id":"@1-/hash@0.1.0","bugs":{"url":"https://github.com/webc-site/npm/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-AiU3EKAwHA1ggBlVxPDpe5shYHYuzaolOrodtCxgLZaxKICjTCdh/vagv95+sUd/+V4RBjAMGvyk44ThZFpAqw==","shasum":"b6fc34ba05b53544dcf04851ac25632ca868da75","tarball":"https://registry.npmjs.org/@1-/hash/-/hash-0.1.0.tgz","fileCount":4,"unpackedSize":5558,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICumAGpW0hZTL0KWyq0V9NnBaHxgbMVFLqYlExsDNhivAiBTymv/7tUT/9APmZAJxLoBhTUCtVGImJ/fDxtR6EXDkA=="}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hash_0.1.0_1780990304833_0.00851899904825193"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-09T07:31:44.638Z","0.1.0":"2026-06-09T07:31:44.959Z","modified":"2026-06-09T07:31:45.239Z"},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"description":"Length-bounded MD5 hash utility / 长度受限的 MD5 哈希工具","homepage":"https://github.com/webc-site/npm/tree/main/hash","keywords":["crypto","hash","length-bounded","md5"],"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"author":{"name":"x-at-01@googlegroups.com"},"bugs":{"url":"https://github.com/webc-site/npm/issues"},"license":"MulanPSL-2.0","readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# @1-/hash : Length-bounded MD5 hash utility\n\n## Features\n\nThis utility provides length-bounded MD5 hashing:\n\n- Returns raw data directly if the input length is 16 bytes or less.\n- Returns a 16-byte MD5 hash if the input length exceeds 16 bytes.\n\nGuarantees the output binary length is always 16 bytes or less. Useful for shortening long keys, optimizing database index storage, and generating compact identifiers.\n\n## Usage\n\n### Hashing Strings\n\n```javascript\nimport strmd5 from \"@1-/hash/strmd5.js\";\n\n// Length <= 16 bytes: returns raw string as a Uint8Array/Buffer\nconst res1 = strmd5(\"1234567890123456\");\n// Returns Buffer: <12 34 56 78 90 12 34 56> (16 bytes)\n\n// Length > 16 bytes: returns MD5 hash Buffer\nconst res2 = strmd5(\"12345678901234567\");\n// Returns 16-byte MD5 hash Buffer of the input\n```\n\n### Hashing Buffers\n\n```javascript\nimport bufmd5 from \"@1-/hash/bufmd5.js\";\n\n// Length <= 16 bytes: returns original Buffer reference\nconst buf1 = Buffer.alloc(10);\nconst res1 = bufmd5(buf1); // res1 === buf1\n\n// Length > 16 bytes: computes and returns MD5 hash Buffer\nconst buf2 = Buffer.alloc(100);\nconst res2 = bufmd5(buf2); // Returns 16-byte MD5 Buffer\n```\n\n## Design Concept\n\nData processing workflow:\n\n![](https://i-01.eu.org/SDvSTOqUjMSd2-NbEl6VqA)\n\nBy enforcing this boundary, short keys retain their original values and readability, while long keys are compressed. This design achieves both efficiency and compactness.\n\n## Tech Stack\n\n- Node.js `node:crypto`\n- Bun (test runner)\n- `@3-/utf8` (high-performance UTF-8 encoder)\n\n## Code Structure\n\n```text\nsrc/\n├── bufmd5.js  # Binary hashing logic\n└── strmd5.js  # String hashing logic\n```\n\n## History\n\nMD5 (Message-Digest Algorithm 5) was designed by Ronald Rivest in 1991 to succeed MD4. Although cryptographic weaknesses (such as collision attacks) were demonstrated by Xiaoyun Wang and other researchers in 2004, MD5 remains widely adopted for non-cryptographic tasks. In checksum verification, caching, and identifier generation, MD5 continues to be a standard tool because of its fast computation and compact 16-byte output. This project extends that pragmatic approach by applying MD5 conditionally.\n\n## About\n\nThis library is developed by [WebC.site](https://webc.site).\n\n[WebC.site](https://webc.site): A new paradigm of web development for AI\n\n---\n\n<a id=\"zh\"></a>\n# @1-/hash : 长度受限的 MD5 哈希工具\n\n## 功能介绍\n\n本工具提供长度受限的 MD5 哈希计算：\n\n- 输入数据长度不大于 16 字节时，直接返回原始数据。\n- 输入数据长度大于 16 字节时，返回 16 字节的 MD5 哈希值。\n\n保证输出结果的二进制长度始终不大于 16 字节。适用于缩短超长键值、优化数据库索引存储及生成紧凑标识符等场景。\n\n## 使用演示\n\n### 字符串哈希\n\n```javascript\nimport strmd5 from \"@1-/hash/strmd5.js\";\n\n// 长度不大于 16 字节，返回原始字符串的 Uint8Array/Buffer\nconst res1 = strmd5(\"1234567890123456\");\n// 返回 Buffer: <12 34 56 78 90 12 34 56> (16 字节)\n\n// 长度大于 16 字节，返回 MD5 哈希 Buffer\nconst res2 = strmd5(\"12345678901234567\");\n// 返回 MD5(12345678901234567) 后的 16 字节 Buffer\n```\n\n### 二进制哈希\n\n```javascript\nimport bufmd5 from \"@1-/hash/bufmd5.js\";\n\n// 长度不大于 16 字节，直接返回原 Buffer 引用\nconst buf1 = Buffer.alloc(10);\nconst res1 = bufmd5(buf1); // res1 === buf1\n\n// 长度大于 16 字节，计算并返回 MD5 哈希 Buffer\nconst buf2 = Buffer.alloc(100);\nconst res2 = bufmd5(buf2); // 返回 16 字节 MD5 Buffer\n```\n\n## 设计思路\n\n数据处理流程：\n\n![](https://i-01.eu.org/d3BG-_n99kXLhfKoBYgI6Q)\n\n通过这一限制，既能对短键名保留其可读性和原始值，又能确保长键名在索引或存储时不会占用过多空间，从而兼顾效率与紧凑性。\n\n## 技术栈\n\n- Node.js `node:crypto`\n- Bun (测试运行器)\n- `@3-/utf8` (高性能 UTF-8 编码器)\n\n## 代码结构\n\n```text\nsrc/\n├── bufmd5.js  # 二进制数据哈希逻辑\n└── strmd5.js  # 字符串数据哈希逻辑\n```\n\n## 历史故事\n\nMD5（Message-Digest Algorithm 5）由密码学家 Ronald Rivest 于 1991 年设计，用以取代存在安全缺陷的 MD4。尽管王小云教授等学者在 2004 年证明了 MD5 碰撞漏洞，使其不再适用于高安全性加密场景，但在数据校验、唯一标识生成等非加密领域，MD5 凭借 16 字节的紧凑输出和优秀的计算性能，依然被广泛应用。本项目继承并延伸了这一实用主义设计。\n\n## 关于\n\n本库由 [WebC.site](https://webc.site) 开发。\n\n[WebC.site](https://webc.site) : 面向人工智能的网站开发新范式\n","readmeFilename":"README.md","_rev":"1-d0b1799eb9c2fba13eba5772170c9815"}