{"id":15439665,"url":"https://github.com/h2non/jshashes","last_synced_at":"2025-05-15T17:08:34.414Z","repository":{"id":2184374,"uuid":"3131890","full_name":"h2non/jshashes","owner":"h2non","description":"Fast and dependency-free cryptographic hashing library for node.js and browsers (supports MD5, SHA1, SHA256, SHA512, RIPEMD, HMAC)","archived":false,"fork":false,"pushed_at":"2022-05-30T10:47:07.000Z","size":301,"stargazers_count":727,"open_issues_count":9,"forks_count":137,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-05-07T23:28:01.578Z","etag":null,"topics":["cryptography","hash-encoding","hashing-algorithm","hexadecimal","hmac","javascript","minim-library","ripemd160","sha1","sha2","sha512"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/h2non.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-01-08T20:41:18.000Z","updated_at":"2025-02-26T20:02:00.000Z","dependencies_parsed_at":"2022-08-25T21:10:42.959Z","dependency_job_id":null,"html_url":"https://github.com/h2non/jshashes","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fjshashes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fjshashes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fjshashes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fjshashes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h2non","download_url":"https://codeload.github.com/h2non/jshashes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384988,"owners_count":22062422,"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":["cryptography","hash-encoding","hashing-algorithm","hexadecimal","hmac","javascript","minim-library","ripemd160","sha1","sha2","sha512"],"created_at":"2024-10-01T19:08:31.949Z","updated_at":"2025-05-15T17:08:29.394Z","avatar_url":"https://github.com/h2non.png","language":"JavaScript","readme":"# jsHashes [![Build Status](https://travis-ci.org/h2non/jshashes.svg)](https://travis-ci.org/h2non/jshashes) [![NPM version](https://img.shields.io/npm/v/jshashes.svg)](https://www.npmjs.com/package/jshashes) [![](https://data.jsdelivr.com/v1/package/npm/jshashes/badge)](https://www.jsdelivr.com/package/npm/jshashes)\n\n`jshashes` is lightweight library implementing the most extended [cryptographic hash function](http://en.wikipedia.org/wiki/Cryptographic_hash_function) algorithms in pure JavaScript (ES5 compliant).\n\nThe goal is to provide an dependency-free, fast and reliable solution for hash algorithms for both client-side and server-side JavaScript environments. \nThe code is fully compatible with the ECMAScript 5 specification and is used in production in browsers and [node.js](http://nodejs.org)/[io.js](http://iojs.org)\n\nIf you are looking for a low-level performance library for the server-side, note that node.js/io.js provides its own native module: [`crypto`](http://nodejs.org/api/crypto.html)\n\n## Supported hash algorithms\n\n* `MD5` (\u003chttp://www.ietf.org/rfc/rfc1321.txt\u003e)\n* `SHA1` (\u003chttp://www.itl.nist.gov/fipspubs/fip180-1.htm\u003e)\n* `SHA256` (\u003chttp://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf\u003e)\n* `SHA512` (\u003chttp://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf\u003e)\n* `HMAC` (\u003chttp://www.ietf.org/rfc/rfc2104.txt\u003e)\n* `RIPEMD-160` (\u003chttp://homes.esat.kuleuven.be/~bosselae/ripemd160.html\u003e)\n\n**Additional functionalities**\n\n* `Base64 encoding/decoding` (\u003chttp://tools.ietf.org/html/rfc3548\u003e)\n* `CRC-32 calculation`\n* `UTF-8 encoding/decoding`\n\n## Environments\n\n- Browsers (ES3)\n- node.js/io.js (all versions)\n- Rhino\n- RingoJS\n\n## Usage\n\nEach algorithm has its respective own instantiable `object`. Here you can see an example of how to create a new instance for each one:\n\n```javascript\n// new MD5 instance\nvar MD5 = new Hashes.MD5\n// new SHA1 instance\nvar SHA1 = new Hashes.SHA1\n// new SHA256 instance\nvar SHA256 =  new Hashes.SHA256\n// new SHA512 instace\nvar SHA512 = new Hashes.SHA512\n// new RIPEMD-160 instace\nvar RMD160 = new Hashes.RMD160\n```\n\nAn example of how to generate an hexadecimal-based hash encoding for each algorithm:\n\n```javascript\n// sample string\nvar str = 'Sample text!'\n// output to console\nconsole.log('MD5: ' + MD5.hex(str))\nconsole.log('SHA1: ' + SHA1.hex(str))\nconsole.log('SHA256: ' + SHA256.hex(str))\nconsole.log('SHA512: ' + SHA512.hex(str))\nconsole.log('RIPEMD-160: ' + RMD160.hex(str))\n```\n\n### Browsers\n\nThis is a simple implementation for a client-side environment:\n\n```html\n\u003chtml\u003e\n\u003chead\u003e\n\u003cscript type=\"text/javascript\" src=\"src/hashes.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n// sample string\nvar str = 'This is a sample text!'\n// new MD5 instance and hexadecimal string encoding\nvar MD5 = new Hashes.MD5().hex(str)\n// output into DOM\ndocument.write('\u003cp\u003eMD5: \u003cb\u003e' + MD5 + '\u003c/b\u003e\u003c/p\u003e')\n\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### node.js / io.js\n\n```javascript\n// require the module\nvar Hashes = require('jshashes')\n// sample string\nvar str = 'This is a sample text!'\n// new SHA1 instance and base64 string encoding\nvar SHA1 = new Hashes.SHA1().b64(str)\n// output to console\nconsole.log('SHA1: ' + SHA1)\n```\n\n### Command-line interface\n\nYou can use the simple command-line interface to generate hashes.\n\n```bash\n$ hashes sha1-hex This is a sample string\n\u003e b6a8501d8a70e74e1dc12a6082102622fdc719bb\n\n# or with quotes\n$ hashes sha1-hex \"This is a sample string\"\n\u003e b6a8501d8a70e74e1dc12a6082102622fdc719bb\n```\n\nFor more information about the options supported, type:\n\n```bash\n$ hashes -h\n```\n\n### Installation\n\nVia [npm](https://npmjs.org)\n\n```\n$ npm install jshashes\n```\n\nVia [Bower](http://bower.io/):\n```\n$ bower install jshashes\n```\n\nVia [Component](https://github.com/component/component):\n```\n$ component install h2non/jshashes\n```\n\nOr loading the script directly:\n```\nhttp://cdn.rawgit.com/h2non/jsHashes/master/hashes.js\n```\n\n## Public methods\n\nEach algorithm `class` provides the following public methods:\n\n* `hex(string)` - Hexadecimal hash encoding from string.\n* `b64(string)` - Base64 hash encoding from string.\n* `any(string,encoding)` - Custom hash algorithm values encoding.\n* `hex_hmac(key,string)` - Hexadecimal hash with HMAC salt key.\n* `b64_hmac(key,string)` - Base64 hash with HMAC salt key.\n* `any_hmac(key,string,encoding)` - Custom hash values encoding with HMAC salt key support.\n* `vm_test()` - Simple self-test to see is working. Returns `this` Object.\n* `setUpperCase(boolean)` - Enable/disable uppercase hexadecimal returned string. Returns `this` Object.\n* `setPad(string)` - Defines a custom base64 pad string. Default is '=' according with the RFC standard. Returns `this` Object.\n* `setUTF8(boolean)` - Enable/disable UTF-8 character encoding. Returns `this` Object.\n\n## Hash encoding formats supported\n\n* Hexadecimal (most extended)\n* Base64\n* Custom hash values `any()` method\n\n## Benchmark\n\nNode.js 0.6.18 running on a VPS Intel I7 930 with 512 MB of RAM (see `server/benchmark.js`)\n\n```javascript\nSimple benchmark test generating 10000 hashes for each algorithm.\nString: \"A0gTtNtKh3RaduBfIo59ZdfTc5pTdOQrkxdZ5EeVOIZh1cXxqPyexKZBg6VlE1KzIz6pd6r1LLIpT5B8THRfcGvbJElwhWBi9ZAE\"\n\n* MD5\n** Done in: 205 milliseconds\n* SHA1\n** Done in: 277 milliseconds\n* SHA256\n** Done in: 525 milliseconds\n* SHA512\n** Done in: 593 milliseconds\n* RMD160\n** Done in: 383 milliseconds\n```\n\nSee `client/benchmark.html` for client-side.\n\n## Notes\n\n* Don't support checksum hash for files on the server-side, only strings-based inputs are supported.\n* It has not been planned to include support for more hash algorithms.\n* The goal is to provide the same JavaScript code in both server and client side, so it isn't planned to improve it in other ways.\n* Only Node.js server-side was tested, so with minimal changes, you can setup `jsHashes` in other server-side JS environment.\n\n## Changelog\n\n* `1.0.7`\n  - Merge #37: fix terminator statement token.\n* `1.0.6`\n  - Fix #34: options `pad` typo.\n* `1.0.4`\n  - Fix CLI script call error when use it from Bash\n  - Added CLI usage example\n* `1.0.3`\n  - Important bugfixes to UTF-8 encoding (broken in 1.0.2) and the RIPEMD-160 hash (broken in 1.0.1). (gh #6)\n  - New test suite for hashes, CRC32, and hmac; run with 'npm test' in node.\n  - Fixed global variable leaks. (gh #13)\n  - CRC32 will now always return positive values. (gh #11)\n  - Added package version property to the exposed Hashes Object\n  - Updated CLI script utility supporting all algorithms (see bin/hashes)\n  - Fixed UTF-8 encoding/decoding error (if input parameter is undefined or invalid)\n* `1.0.2`\n  - Performance improvements and minimal refactor (length property caching, literal notation)\n  - Available from Bower package manager\n* `1.0.1`\n  - Refactoring (hoisting, coercion, removed redundant functions, scoping, restructure...)\n  - Performance improves\n  - JSLint validation (except bitwise operators)\n  - Now the library can be used like a AMD CommonJS module\n  - Updated documentation\n  - New folders structure\n  - Added closure compiled and minimized library version\n  - Available from Jam package manager\n* `0.1.5b`\n  - Added index.js for easy call the module in Node.js\n  - Updated documentation\n* `0.1.4b`\n  - Now declaring objects using Literal Notation.\n  - Solved syntax errors on minimized version (jshashes.min.js)\n  - Added benchmark test and sample\n* `0.1.3b`\n  - Starting non-redundancy code refactorization\n  - Added `Helpers` Object with some global functions\n  - Added native support for Base64 provided as `class`\n  - Added CRC-32 calculation support\n  - Added URL encode/decode helpers functions\n* `0.1.2b`\n  - SHA1 error fixed.\n  - General code changes (renaming classes, private methods, new methods...).\n  - Changing library namespace to 'Hashes'.\n  - Starting code documentation.\n  - Added new examples of how to use.\n* `0.1.1b`\n  - Minimal library improvements.\n  - There has been added some samples, like how to use it and support for NPM package.\n* `0.1.0b`\n  - First release: the code is stable, but the library is still beta and must be improved and documented.\n\n## TODO\n\n* Performance benchmarking\n\n## Authors\n\n### Library author\n\n* [Tomas Aparicio](https://github.com/h2non/)\n\n### Original algorithm authors\n\n* [Paul Johnston](http://pajhome.org.uk/crypt/md5/)\n* Angel Marin (SHA256)\n* Jeremy Lin (RIPEMD-160)\n\n### Other contributors\n\n* [C. Scott Ananian](https://github.com/cscott)\n* Greg Holt\n* Andrew Kepert\n* Ydnar\n* Lostinet\n\n## License\n\njsHashes is released under `New BSD` license. See `LICENSE` file.\n\n## Issues\n\nFeel free to report any issue you experiment via Github \u003chttps://github.com/h2non/jsHashes/issues\u003e.\n","funding_links":[],"categories":["Frameworks and Libs"],"sub_categories":["JavaScript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Fjshashes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh2non%2Fjshashes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Fjshashes/lists"}