{"id":23507372,"url":"https://github.com/simplyhexagonal/string-crypto","last_synced_at":"2025-04-16T02:19:24.082Z","repository":{"id":57372384,"uuid":"300441995","full_name":"simplyhexagonal/string-crypto","owner":"simplyhexagonal","description":"Small and simple (yet secure) library to encrypt and decrypt strings using PBKDF2 for key derivation and AES (defaulted to 256-bit / SHA512)","archived":false,"fork":false,"pushed_at":"2024-04-19T17:39:29.000Z","size":2361,"stargazers_count":22,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T11:38:22.286Z","etag":null,"topics":["aes","crypto","cryptography","javascript","javascript-library","pbkdf2","rollup","runkit","string-crypto","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/string-crypto","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplyhexagonal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2020-10-01T22:35:23.000Z","updated_at":"2025-04-02T13:08:08.000Z","dependencies_parsed_at":"2024-04-13T23:47:49.928Z","dependency_job_id":null,"html_url":"https://github.com/simplyhexagonal/string-crypto","commit_stats":{"total_commits":41,"total_committers":2,"mean_commits":20.5,"dds":0.09756097560975607,"last_synced_commit":"126097ffa3cce80e82c867b25906c1dcc242f430"},"previous_names":["jeanlescure/string-crypto"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fstring-crypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fstring-crypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fstring-crypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fstring-crypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplyhexagonal","download_url":"https://codeload.github.com/simplyhexagonal/string-crypto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248953432,"owners_count":21188637,"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":["aes","crypto","cryptography","javascript","javascript-library","pbkdf2","rollup","runkit","string-crypto","typescript"],"created_at":"2024-12-25T10:18:17.530Z","updated_at":"2025-04-16T02:19:24.058Z","avatar_url":"https://github.com/simplyhexagonal.png","language":"JavaScript","funding_links":["https://www.buymeacoffee.com/jeanlescure","https://www.patreon.com/jeanlescure"],"categories":[],"sub_categories":[],"readme":"![String Crypto logo depicting a ball of yarn being weaved by a vintage looking key](https://assets.jeanlescure.io/string-crypto-logo.svg)\n\n# String Crypto\n\n![Tests](https://github.com/simplyhexagonal/string-crypto/workflows/tests/badge.svg)\n[![Try string-crypto on RunKit](https://badge.runkitcdn.com/string-crypto.svg)](https://npm.runkit.com/string-crypto)\n[![NPM Downloads](https://img.shields.io/npm/dt/string-crypto.svg?maxAge=2592000)](https://npmjs.com/package/string-crypto)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\nSmall, simple, and secure library to encrypt and decrypt strings using PBKDF2 for key derivation and AES (defaulted to 256-bit / SHA512).\n\nThis project is open to updates by its users, I ensure that PRs are relevant to the community.\nIn other words, if you find a bug or want a new feature, please help us by becoming one of the\n[contributors](#contributors-) ✌️ ! See the [contributing section](#contributing).\n\n# Breaking Changes in v3\n\n- **Digest Option Removed**: The ability to specify a digest method for key derivation has been removed due to the underlying library (`crypto-js`) not supporting this functionality directly. We switched to using `crypto-js` since Node's `crypto` is [commonly breaking](https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported/73287371) due to a missmatch with openssl versions.\n- **Key Size Specification**: Key size can now be specified in bits as an option when encrypting or decrypting, providing users with the flexibility to define the strength of encryption according to their needs.\n- **Default Salt Generation**: The default salt is now generated dynamically for each encryption operation if not specified by the user, enhancing security by preventing the use of static salts.\n\n## Features\n\n- Encryption and decryption of strings using PBKDF2 (for key derivation) and AES (Advanced Encryption Standard) in CBC mode.\n- Dynamic generation of a secure random salt for each encryption operation when not specified.\n- Customizable number of iterations for key derivation, enhancing the security against brute force attacks.\n- Key size can be specified in bits, allowing for AES-128, AES-192, and AES-256 encryption strengths.\n- Simplified CLI and library interfaces for straightforward usage in encrypting and decrypting strings.\n- Secure random initialization vector (IV) generation for each encryption operation, ensuring ciphertext uniqueness.\n\n## Like this module? ❤\n\nPlease consider:\n\n- [Buying me a coffee](https://www.buymeacoffee.com/jeanlescure) ☕\n- Supporting me on [Patreon](https://www.patreon.com/jeanlescure) 🏆\n- Starring this repo on [Github](https://github.com/simplyhexagonal/string-crypto) 🌟\n\n## Usage CLI\n\n### Encrypting a String\n\nTo encrypt a string, use the `encrypt` command with the required options:\n\n```bash\nnpx string-crypto encrypt --string \"Your String Here\" --password \"YourPassword\"\n```\n\nOptional parameters:\n\n- `--salt`: Custom salt for encryption. If omitted, a random salt will be used.\n- `--iterations`: Number of iterations (default is 1000).\n- `--keySize`: Key size in bits (default is 256).\n\n### Decrypting a String\n\nTo decrypt a string, use the `decrypt` command with the required options:\n\n```bash\nnpx string-crypto decrypt --string \"EncryptedStringHere\" --password \"YourPassword\"\n```\n\nOptional parameters are the same as for encryption, except `--digest` is no longer available.\n\n### Help\n\nFor more information or to see all available options, you can use the `-h` or `--help` flag:\n\n```bash\nnpx string-crypto --help\n```\n\n## Usage Library\n\n```bash\nnpm i string-crypto\n```\n\n```bash\npnpm i string-crypto\n```\n\n```bash\nyarn add string-crypto\n```\n\n```ts\nimport StringCrypto from 'string-crypto';\n\nconst stringToProtect = 'What is the largest (rational) number n such that there are positive integers p, q, r such that 1 - 1/p - 1/q - 1/r = 1/n?';\n\nconst password = 'Oh-no,not-again';\n\nconst sc = new StringCrypto();\n\nlet encryptedString = sc.encryptString(stringToProtect, password);\n\nconsole.log('Encrypted String:', encryptedString);\n\nconsole.log('Decrypted String:', sc.decryptString(encryptedString, password));\n```\n\n## Options\n\n```ts\nconst options = {\n  salt: '2f0ijf2039j23r09j2fg45o9ng98um4o',\n  iterations: 1000,\n  keySize: 256, // Specify key size in bits\n};\n\nconst sc = new StringCrypto(options);\n```\n\n## Development and build scripts\n\nI chose Rollup to handle the transpiling, compression, and any other transformations needed to get\nyour Typescript code running as quickly and performant as possible.\n\nThis repo uses `runkit.js` to validate code sanity. Why? Because [www.npmjs.com](https://www.npmjs.com/)\nuses [Runkit](https://runkit.com/home) to allow potential users to play with your module, live on\ntheir browser, which is one of the best ways to convince someone to use your modules in their code.\nRunkit will look for the `runkit.js` by default and display that as the initial playground for the\nuser, so by making it the default validation method during development, this encourages proper\ncommunication with the users of your code.\n\n**Development**\n\n```\nyarn dev\n```\n\nUses [concurrently]() to run Rollup in watch mode (which means it will transpile to `dist` when you\nsave changes to your code), as well as Nodemon to listen for changes in the `dist` directory and\nre-run the `runkit.js` as you modify your source! This includes running node with the `--inspect`\nflag so you can inspect your code using [Google Chrome Dev Tools](https://nodejs.org/en/docs/guides/debugging-getting-started/)\n(by opening `chrome://inspect` in your browser), you're welcome ;)\n\n**Build**\n\n```\nyarn build\n```\n\nThis command will build the `dist/index.js`, uglified and tree-shaken so it loads/runs faster.\n\nIt also generates a source map and a `dist/index.d.ts` type file for Typescript importing convenience.\n\n## Contributing\n\nYes, thank you! This plugin is community-driven, most of its features are from different authors.\nPlease update the docs and tests and add your name to the `package.json` file.\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://jeanlescure.cr\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/3330339?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJean Lescure\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-jeanlescure\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/jeanlescure/string-crypto/commits?author=jeanlescure\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#userTesting-jeanlescure\" title=\"User Testing\"\u003e📓\u003c/a\u003e \u003ca href=\"https://github.com/jeanlescure/string-crypto/commits?author=jeanlescure\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"#example-jeanlescure\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"https://github.com/jeanlescure/string-crypto/commits?author=jeanlescure\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://dianalu.design\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/1036995?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDiana Lescure\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/jeanlescure/string-crypto/commits?author=DiLescure\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/jeanlescure/string-crypto/pulls?q=is%3Apr+reviewed-by%3ADiLescure\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e \u003ca href=\"#design-DiLescure\" title=\"Design\"\u003e🎨\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplyhexagonal%2Fstring-crypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplyhexagonal%2Fstring-crypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplyhexagonal%2Fstring-crypto/lists"}