{"id":15408984,"url":"https://github.com/ajimae/ncrypt-js","last_synced_at":"2026-02-06T07:29:27.320Z","repository":{"id":35085086,"uuid":"203824455","full_name":"ajimae/ncrypt-js","owner":"ajimae","description":"A light weight javascript data encryption and decryption library","archived":false,"fork":false,"pushed_at":"2024-10-25T02:37:42.000Z","size":213,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T06:48:17.771Z","etag":null,"topics":["cipher","crypto","cryptography","decipher","decrypt","decryption","ecmascript5","encrypt","encryption","javascript-library","ncrypt-js","simplecryptojs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajimae.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-22T15:37:23.000Z","updated_at":"2025-03-13T02:49:53.000Z","dependencies_parsed_at":"2024-06-19T04:08:35.948Z","dependency_job_id":"53169c0a-fe46-47ba-9ab7-056d9a1fd36f","html_url":"https://github.com/ajimae/ncrypt-js","commit_stats":{"total_commits":28,"total_committers":4,"mean_commits":7.0,"dds":0.3928571428571429,"last_synced_commit":"a3976a641e94db9ded10cbbe940fccdc65098656"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimae%2Fncrypt-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimae%2Fncrypt-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimae%2Fncrypt-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimae%2Fncrypt-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajimae","download_url":"https://codeload.github.com/ajimae/ncrypt-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248815540,"owners_count":21165941,"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":["cipher","crypto","cryptography","decipher","decrypt","decryption","ecmascript5","encrypt","encryption","javascript-library","ncrypt-js","simplecryptojs","typescript"],"created_at":"2024-10-01T16:36:21.238Z","updated_at":"2026-02-06T07:29:27.314Z","avatar_url":"https://github.com/ajimae.png","language":"TypeScript","readme":"# NcryptJs\n\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ajimae/ncrypt-js/.github%2Fworkflows%2Fci.yml)\n [![Coverage Status](https://coveralls.io/repos/github/ajimae/ncrypt-js/badge.svg)](https://coveralls.io/github/ajimae/ncrypt-js) ![NPM Downloads](https://img.shields.io/npm/dw/ncrypt-js)\n\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/ajimae/ncrypt-js)](https://github.com/ajimae/ncrypt-js/releases) [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ajimae/ncrypt-js)](https://github/languages/code-size/ajimae/ncrypt-js) [![GitHub issues](https://img.shields.io/github/issues/ajimae/ncrypt-js)](https://github.com/ajimae/ncrypt-js/issues) [![NPM](https://img.shields.io/npm/l/ncrypt-js)](https://www.npmjs.com/package/ncrypt-js/v/2.0.0#license)\n\n**_NcryptJs_** is a light weight javascript data encryption and decryption library. This library implements the nodejs default crypto functionality as a mid-channel cipher in addition to a simple and elegant custom data encoding and encryption algorithm.\n\n## Contents\n\n* [NcryptJs](#NcryptJs)\n  * [Contents](#contents)\n  * [Getting Started](#getting-started)\n    * [Installation](#installation)\n  * [Documentation](#documentation)\n    * [NcryptJs Methods](#ncryptjs-methods)\n    * [Using the `randomString()` methods](#using-randomstring-method)\n    * [Using `encrypt()` and `decrypt()` methods](#using-encrypt-and-decrypt-methods)\n    * [String Encryption](#string-encryption)\n    * [Object Encryption](#object-encryption)\n    * [Using password hashing methods](#using-password-hashing-methods)\n  * [Built With](#built-with)\n  * [Contribution](#contribution)\n  * [Version Management](#version-management)\n  * [Authors](#authors)\n  * [License](#license)\n  * [Acknowledgments](#acknowledgments)\n\n\u003c!-- ## Changes Log (What's New)\n\n**What's New in 2.2.0**\n\n* Fix CDN release, setting webpack output as UMD with default library name of SimpleCrypto.\n* CDN now have two file you may use, the distribution file and minified distribution one.\n\nFor full changelog, please refers to [CHANGELOG](CHANGELOG.md) file. --\u003e\n\n## Getting Started\n\nThis library is available through these javascript node package manager [npm](https://www.npmjs.org/) and [yarn](https://www.yarnpkg.com/).\n\n## Installation\n\nTo use this library, first ensure you have a package manager initialized either with [npm](https://www.npmjs.org/) or [yarn](https://www.yarnpkg.com/)\n\n```bash\n# for npm use:\nnpm install --save ncrypt-js\n\n# for yarn use:\nyarn add ncrypt-js\n```\n\nTo include **_ncrypt-js_** in your project. use one of these:\n\n```js\n// ES6 and later\nimport ncrypt from \"ncrypt-js\";\n// or import { ncrypt } from \"ncrypt-js\"\n```\n\nHowever, if you are using ECMAScript 5 and older, use the require statement:\n\n```js\n// ES5 and older\nvar { ncrypt } = require(\"ncrypt-js\");\n```\n\n## Documentation\n\n**_NcryptJs_** is a simple library with only two two exposed functions. This is all intentional mainly to keep everything simple. This is a complete documentation of the library and how to use it in your project. All examples work on both ECMAScript 6 (and later) and ECMAScript 5 (and older).\n\n### NcryptJs Methods\n\n\n### List of **_NcryptJs_** Methods.\n\n\n\n| Methods                                                                                              | Description                                                                                            | Parameters                                                                                             | Return                                                                                                 |\n| -------------------------------------------------------------                                          | --------------------------------------------------------------------------------------                 | -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                                                                             | ----------------------------------------------------------------------------------------------------------------                                                                                                |\n| [_static_] **randomString()**                                                                                          | Random String.                                                                                     |**size**: _number_ - An optional size of the generated `randomBytes`. \u003cbr/\u003e**enc:** _base64/hex_ - Encoding used for encoding the `randomBytes` defaults to _`base64`_ |**encoded**: _string_ - encoded string.                                                                    |\n| [_static_] **generate()**                                                                                          | Generates a hashed password.                                                                                     |**password**: _string_ - The password to hash. \u003cbr/\u003e**options**: _object_ - Optional configuration object (see below). |**hashedPassword**: _string_ - The hashed password string.                                                                    |\n| [_static_] **verify()**                                                                                          | Verifies a password against a hashed password.                                                                 | **password**: _string_ - The password to verify. \u003cbr/\u003e**hashedPassword**: _string_ - The hashed password to verify against. \u003cbr/\u003e**options**: _object_ - Optional configuration object (see below).                        | **boolean** - Returns `true` if the password matches the hash, `false` otherwise.\n| [_static_] **isHashed()**                                                                                          | Checks if a string is a hashed password.                                                                 | **password**: _string_ - The string to check. \u003cbr/\u003e**options**: _object_ - Optional configuration object (see below).                        | **boolean** - Returns `true` if the string appears to be a hashed password, `false` otherwise.\n| **encrypt()**                                                                                          | Encrypts data.                                                                                     |**data**: _object/string/number/boolean_ - The data to be encrypted. \u003cbr/\u003e|**ciphered**: _string_ - encrypted data.                                                                    |\n| **decrypt()**                                                                                          | Decrypts the encrypted or ciphered data                                                                 | **encodedData**: string - The encrypted data: _string_ to be decrypted.                        | **data**: _string/object/number/boolean_ - The decrypted or original data (it might be string or object, depends on the initial input data type).\n\n\n### Using randomString method\n\nThe `randomString()` static method can generate [random bytes](https://nodejs.org/api/crypto.html#cryptorandombytessize-callback) encoded into a `hexadecimal` or `base64` strings. This string can be useful in a variety of use cases e.g to generate database ids, to generate a unique string for a list, a unique serial strings, api keys etc.\n\n```ts\nvar { ncrypt } = require('ncrypt-js'); // or import ncrypt from 'ncrypt-js'\n\nvar randomStr = ncrypt.randomString(8, 'base64');\nconsole.log(randomStr) // t78WcmYAFOY=\n\n// signature\nncrypt.randomString(size?: number, enc?: 'base64' | 'hex');\n```\n\n### Using encrypt() and decrypt() methods\nThe `encrypt()` and `decrypt()` methods as of version 2.0.0 directly importing or invoking these methods is `deprecated`, an object must first be created with a secret, before the methods can then be invoked on the created object.\n\nTo `encrypt` and `decrypt` data, simply use `encrypt()` and `decrypt()` methods respectively. This will use `AES-256-CBC` encryption algorithm as the mid-channel cipher.\n\n```diff\n- var { encrypt, decrypt } = require(\"ncrypt-js\");\n+ var { ncrypt } = require(\"ncrypt-js\");\n\n\nvar data = \"Hello World!\";\nvar _secretKey = \"some-super-secret-key\";\n\n+ var { encrypt, decrypt } = new ncrypt(_secretKey);\n\n// encrypting super sensitive data here\n- var encryptedData = encrypt(data, _secretKey);\n+ var encryptedData = encrypt(data);\n\nconsole.log(\"Encryption process...\");\nconsole.log(\"Plain Text    : \" + data);\nconsole.log(\"Cipher Text   : \" + encryptedData);\n\n// decrypting the encrypted super sensitive data here\nvar decryptedData = decrypt(encryptedData);\nconsole.log(\"... and then decryption...\");\nconsole.log(\"Decipher Text : \" + decryptedData);\nconsole.log(\"...done.\");\n```\n\n### String Encryption\n\n```javascript\nvar { ncrypt } = require(\"ncrypt-js\");\n\nvar data = \"Hello World!\";\nvar _secretKey = \"some-super-secret-key\";\n\nvar ncryptObject = new ncrypt(_secretKey);\n\n// encrypting super sensitive data here\nvar encryptedData = ncryptObject.encrypt(data);\nconsole.log(\"Encryption process...\");\nconsole.log(\"Plain Text    : \" + data);\nconsole.log(\"Cipher Text   : \" + encryptedData);\n\n// decrypted super encrypted data here\nvar decryptedData = ncryptObject.decrypt(encryptedData);\nconsole.log(\"... and then decryption...\");\nconsole.log(\"Decipher Text : \" + decryptedData);\nconsole.log(\"...done.\");\n```\n\n### Object Encryption\n\nEncryption and decryption of JavaScript object literal has never been simpler than this. \n\nTo encrypt and decrypt JavaScript object literal, simply use `encrypt()` and `decrypt()` function from an instance. This will use AES-CBC encryption algorithm.\n\n\n```javascript\nvar { ncrypt } = require(\"ncrypt-js\");\n\nvar _secretKey = \"some-super-secret-key\";\nvar object = {\n  NycryptJs: \"is cool and fun.\",\n  You: \"should try it!\"\n}\n\nvar ncryptObject = new ncrypt('ncrypt-js');\n\n// encrypting super sensitive data here\nvar encryptedObject = ncryptObject.encrypt(object);\nconsole.log(\"Encryption process...\");\nconsole.log(\"Plain Object     : \", object);\nconsole.log(\"Encrypted Object : \" + encryptedObject);\n\n// decrypted super sensitive data here\nvar decryptedObject = ncryptObject.decrypt(encryptedObject);\nconsole.log(\"... and then decryption...\");\nconsole.log(\"Decipher Text : \", decryptedObject);\nconsole.log(\"...done.\");\n````\nIf you are using any sort of environmental key-value store, e.g `.env` and for additional security, you can add the following to your environment.\n\n```bash\n# .env\n\n# used internally to set the `key`\nKEY='sshhhh this is a super secret key'\n\n# used internally to set the `encoding` - ['base64' | 'binary' | 'hex' | 'ucs-2' | 'ucs2' | 'utf16le']\nNCRYPT_ENC='hex'\n\nSECRET='this is our hashing secret'\n```\nWhen creating your object, you can use the `SECRET` from your environment e.g:\n\n```js\nvar { ncrypt } = require('ncrypt-js');\nvar { encrypt, decrypt } = new ncrypt(process.env.SECRET);\n...\n```\n_**NOTE:** The secret is required to decrypt the encrypted data, if the secret used to encrypt a specific data is lost, then that data cannot be decrypted._\n\n_Same goes for encoding, if data was encrypted using `hex` encoding format, decrypting with a `base64` encoding or other encoding format and vise versa will not work_\n\n### Using password hashing methods\n\nThe `generate()`, `verify()`, and `isHashed()` static methods provide secure password hashing and verification functionality. These methods use HMAC (Hash-based Message Authentication Code) for password hashing.\n\n#### Generating a hashed password\n\nThe `generate()` method creates a secure hash of a password with a randomly generated salt.\n\n```ts\nvar { ncrypt } = require('ncrypt-js'); // or import ncrypt from 'ncrypt-js'\n\nvar password = \"mySecurePassword123\";\nvar hashedPassword = ncrypt.generate(password);\nconsole.log(hashedPassword); // sha1$abc12345$1$hashedvalue...\n\n// signature\nncrypt.generate(password: string, options?: {\n  algorithm?: string;          // Hash algorithm (default: 'sha1')\n  saltLength?: number;         // Salt length in characters (default: 8)\n  iterations?: number;         // Number of hash iterations (default: 1)\n  encoding?: 'hex' | 'base64'; // Encoding format (default: 'hex')\n  separator?: string;          // Separator character (default: '$')\n});\n```\n\n#### Verifying a password\n\nThe `verify()` method checks if a plain text password matches a previously hashed password.\n\n```ts\nvar { ncrypt } = require('ncrypt-js');\n\nvar password = \"mySecurePassword123\";\nvar hashedPassword = ncrypt.generate(password);\n\n// Later, verify the password\nvar isValid = ncrypt.verify(password, hashedPassword);\nconsole.log(isValid);           // true\n\n// signature\nncrypt.verify(password: string, hashedPassword: string, options?: {\n  encoding?: 'hex' | 'base64';  // Encoding format (default: 'hex')\n  separator?: string;           // Separator character (default: '$')\n});\n```\n\n#### Checking if a string is hashed\n\nThe `isHashed()` method checks if a string appears to be a hashed password by verifying its format.\n\n```ts\nvar { ncrypt } = require('ncrypt-js');\n\nvar hashedPassword = ncrypt.generate(\"password123\");\nvar isHashed = ncrypt.isHashed(hashedPassword);\nconsole.log(isHashed); // true\n\nvar plainPassword = \"password123\";\nvar isHashed = ncrypt.isHashed(plainPassword);\nconsole.log(isHashed); // false\n\n// signature\nncrypt.isHashed(password: string, options?: {\n  separator?: string; // Separator character (default: '$')\n});\n```\n\n#### Advanced usage with custom options\n\nYou can customize the hashing algorithm, salt length, iterations, encoding, and separator:\n\n```ts\nvar { ncrypt } = require('ncrypt-js');\n\n// Generate with custom options\nvar hashedPassword = ncrypt.generate(\"password123\", {\n  algorithm: \"sha256\",   // Use SHA-256 instead of SHA-1\n  saltLength: 16,        // Use 16 character salt\n  iterations: 1000,      // Apply hashing 1000 times\n  encoding: \"base64\",    // Use base64 encoding\n  separator: \".\"         // Use '.' as separator instead of '$'\n});\n\n// Verify with matching options\nvar isValid = ncrypt.verify(\"password123\", hashedPassword, {\n  encoding: \"base64\",\n  separator: \".\"\n});\nconsole.log(isValid); // true\n```\n\n**Available hash algorithms:** Any algorithm supported by Node.js `crypto.createHmac()`, such as `'sha1'`, `'sha256'`, `'sha512'`, `'md5'`, etc.\n\n**Note:** The `encoding` and `separator` options must match between `generate()` and `verify()` calls for verification to succeed. To be safe, ensure you create a single options object and use the same object everywhere.\n\n```ts\nconst same_options_obj = {\n  ...\n}\n\nncrypt.generate(\"pass\", same_options_obj)\nncrypt.verify(\"pass\", hasedPass, same_options_obj)\n```\n\n## Built With \n\nWritten in [TypeScript](https://typscriptlang.org/), built into ECMAScript 5 using the TypeScript compiler.\n\n## Contribution\n\nTo contribute, simply fork this project, and issue a pull request.\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for version management. For the versions available, see the [tags on this repository](https://github.com/ajimae/ncrypt-js/tags).\n\n## Authors\n\n* **Chukwuemeka Ajima** - _Initial work_ - [ajimae](https://github.com/ajimae)\n\n\u003c!-- Feel free to include a CONTRIBUTORS.md file and modify this contributors secion --\u003e\n\u003c!-- See also the list of [contributors](CONTRIBUTORS) who participated in this project. --\u003e\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n\n## Acknowledgments\n\n* This library was developed to simplify how data is encrypted and decrypted in javascript.\n* Made available by open source and special thanks to [Shahid](https://twitter.com/codeforgeek) for his super simple [article](https://codeforgeek.com/encrypt-and-decrypt-data-in-node-js/) on node core encryption (crypto) library.\n* Thanks to [danang-id](https://github.com/danang-id) whose [README](https://github.com/danang-id/simple-crypto-js/blob/master/README.md) was very insightful and [Jorgeblom](https://stackoverflow.com/users/2861702/jorgeblom) for his custom cipher algorithm on this stackoverflow [answer](https://stackoverflow.com/a/54026460/4907157)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajimae%2Fncrypt-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajimae%2Fncrypt-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajimae%2Fncrypt-js/lists"}