{"id":14384404,"url":"https://github.com/juhoen/hybrid-crypto-js","last_synced_at":"2025-09-14T06:14:51.171Z","repository":{"id":49575612,"uuid":"112479586","full_name":"juhoen/hybrid-crypto-js","owner":"juhoen","description":"RSA+AES hybrid encryption implementation for JavaScript. Works with Node.js, React Native and modern browsers.","archived":false,"fork":false,"pushed_at":"2021-06-13T23:55:49.000Z","size":830,"stargazers_count":142,"open_issues_count":11,"forks_count":40,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-13T22:33:59.895Z","etag":null,"topics":["aes","aes-256","decrypt","decryption","encrypt","encryption","hybrid","hybrid-crypto-js","node","nodejs","react-native","rsa","rsa-aes","web","webpack"],"latest_commit_sha":null,"homepage":"https://github.com/juhoen/hybrid-crypto-js","language":"JavaScript","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/juhoen.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":"2017-11-29T13:36:21.000Z","updated_at":"2024-11-26T10:03:07.000Z","dependencies_parsed_at":"2022-09-06T06:10:59.448Z","dependency_job_id":null,"html_url":"https://github.com/juhoen/hybrid-crypto-js","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juhoen%2Fhybrid-crypto-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juhoen%2Fhybrid-crypto-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juhoen%2Fhybrid-crypto-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juhoen%2Fhybrid-crypto-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juhoen","download_url":"https://codeload.github.com/juhoen/hybrid-crypto-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230716506,"owners_count":18269779,"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","aes-256","decrypt","decryption","encrypt","encryption","hybrid","hybrid-crypto-js","node","nodejs","react-native","rsa","rsa-aes","web","webpack"],"created_at":"2024-08-28T18:01:21.732Z","updated_at":"2024-12-21T12:30:33.934Z","avatar_url":"https://github.com/juhoen.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Hybrid Crypto JS\n\n[![NPM](https://nodei.co/npm/hybrid-crypto-js.png)](https://nodei.co/npm/hybrid-crypto-js/)\n\n## Introduction\n\n\u003ca name=\"introduction\"\u003e\u003c/a\u003e\n\n_Hybrid Crypto JS_ is a hybrid (RSA+AES) encryption and decryption toolkit for JavaScript. _Hybrid Crypto JS_ combines RSA and AES encryption algorithms, making it possible to encrypt and decrypt large messages efficiently. This cross-platform library is based on [Forge](https://github.com/digitalbazaar/forge). _Hybrid Crypto JS_ can be used in browsers, Node.js, or React Native.\n\n## Documentation\n\n\u003ca name=\"documentation\"\u003e\u003c/a\u003e\n\n**Getting started**\n\n-   [Introduction](#introduction)\n-   [Documentation](#documentation)\n-   [Installation](#installation)\n\n**Features**\n\n-   [Initialization](#initialization)\n-   [Encryption](#encryption)\n-   [Decryption](#decryption)\n-   [Signatures](#signatures)\n-   [Verifying](#verifying)\n-   [RSA key pairs](#rsa-key-pairs)\n\n### Installation\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n\n```\nnpm install hybrid-crypto-js\n```\n\n### Importing\n\n**Node.js**\n\n```js\nvar RSA = require('hybrid-crypto-js').RSA;\nvar Crypt = require('hybrid-crypto-js').Crypt;\n```\n\n**React Native**\n\n```js\nimport { Crypt, RSA } from 'hybrid-crypto-js';\n```\n\n**Web**\n\nDownload minified _hybrid-crypto.min.js_ file [here](https://raw.githubusercontent.com/juhoen/hybrid-crypto-js/master/web/hybrid-crypto.min.js).\n\n```html\n\u003cscript type=\"text/javascript\" src=\"hybrid-crypto.min.js\"\u003e\u003c/script\u003e\n```\n\n## Features\n\n### Initialization\n\n\u003ca name=\"initialization\"\u003e\u003c/a\u003e\n\n```js\n// Basic initialization\nvar crypt = new Crypt();\nvar rsa = new RSA();\n\n// Increase amount of entropy\nvar entropy = 'Random string, integer or float';\nvar crypt = new Crypt({ entropy: entropy });\nvar rsa = new RSA({ entropy: entropy });\n\n// Select default message digest\nvar crypt = new Crypt({ md: 'sha512' });\n\n// Select AES or RSA standard\nvar crypt = new Crypt({\n    // Default AES standard is AES-CBC. Options are:\n    // AES-ECB, AES-CBC, AES-CFB, AES-OFB, AES-CTR, AES-GCM, 3DES-ECB, 3DES-CBC, DES-ECB, DES-CBC\n    aesStandard: 'AES-CBC',\n    // Default RSA standard is RSA-OAEP. Options are:\n    // RSA-OAEP, RSAES-PKCS1-V1_5\n    rsaStandard: 'RSA-OAEP',\n});\n\n// Alternate AES keysize (some AES algorithms requires specific key size)\nvar crypt = new Crypt({\n    aesKeySize: 192, // Defaults to 256\n});\n```\n\n### Encryption\n\n\u003ca name=\"encryption\"\u003e\u003c/a\u003e\n\n_Hybrid Crypto JS_ provides basic encryption function that also supports multiple RSA keys, with or without [signature](#signatures). An encrypted message is a JSON formatted string.\n\n```js\nvar message = 'Hello world!';\n\n// Encryption with one public RSA key\nvar encrypted = crypt.encrypt(publicKey, message);\n\n// Function also supports encryption with multiple RSA public keys\nvar encrypted = crypt.encrypt([publicKey1, publicKey2, publicKey3], message);\n\n// Encryption with signature\nvar encrypted = crypt.encrypt(publicKey, message, signature);\n```\n\n**Pretty-printed sample output**\n\n```js\n{\n    \"v\": \"hybrid-crypto-js_0.1.2\",        // Current package version\n    \"iv\": \"CmtyaZTyzoAp1mTNUTztic0v1...\", // Initialization vector\n    \"keys\": {                             // Encrypted AES keys by RSA fingerprints\n        \"85:3d:10:e1:56...\": \"bHaTF9...\",\n        \"d3:48:6a:e9:13...\": \"t9eds3...\"\n    },\n    \"cipher\": \"+iwVFsC2dECBQvwcm9DND...\"  // Actual encrypted message\n    \"signature\": \"sdL93kfdm12feds3C2...\"  // Signature (optional)\n}\n\n```\n\n### Decryption\n\n\u003ca name=\"decryption\"\u003e\u003c/a\u003e\n\nDecrypting message with _Hybrid Crypto JS_ is as easy as encrypting. Decrypt function can decrypt any message which has been encrypted with key pair's public key. The decrypted message is a JSON object containing a message and an optional signature.\n\n```js\nvar encrypted = '{\"v\":\"hybrid-crypto-js_0.1.0\",\"iv\":\"CmtyaZTyzoAp1mTN...';\n\n// Decrypt encryped message with private RSA key\nvar decrypted = crypt.decrypt(privateKey, encrypted);\n\n// Get decrypted message\nvar message = decrypted.message;\n```\n\n**Sample output**\n\n```js\n{\n    message: \"Hello world!\",            // Actual decrypted message\n    signature: \"sdL93kfdm12feds3C2...\"  // Signature (optional)\n}\n```\n\n### Signatures\n\n\u003ca name=\"signatures\"\u003e\u003c/a\u003e\n\n_Hybrid Crypto JS_ provides simple message signing. The encrypted message can be signed with the issuer's private key.\n\n```js\nvar message = 'Hello world!';\n\n// Create a signature with ISSUER's private RSA key\nvar signature = crypt.signature(issuerPrivateKey, message);\n\n// Encrypt message with RECEIVERS public RSA key and attach the signature\nvar encrypted = crypt.encrypt(receiverPublicKey, message, signature);\n\n// Select default message digest\nvar crypt = new Crypt({\n    md: 'sha512', // Options: sha1, sha256, sha384, sha512, and md5\n});\n```\n\n### Verifying\n\n\u003ca name=\"verifying\"\u003e\u003c/a\u003e\n\nThe message receiver needs to have a message issuer's public RSA key in order to verify the message issuer.\n\n```js\n// Encrypted message with signature\nvar encrypted = '{\"v\":\"hybri... ...\"signature\":\"sdL93kfd...';\n\n// Decrypt message with own (RECEIVER) private key\nvar decrypted = crypt.decrypt(receiverPrivateKey, encrypted);\n\n// Verify message with ISSUER's public key\nvar verified = crypt.verify(\n    issuerPublicKey,\n    decrypted.signature,\n    decrypted.message,\n);\n```\n\nVerification function returns _true_ or _false_ depending on whether the verification was successful.\n\n### RSA key pairs\n\n\u003ca name=\"rsa-key-pairs\"\u003e\u003c/a\u003e\n\n_Hybrid Crypto JS_ RSA key generation function is based in [Forge](https://github.com/digitalbazaar/forge#rsa) key pair generation function. As a difference, _Hybrid Crypto JS_ returns key pair in PEM format.\n\n```js\n// Initialize RSA-class\nvar rsa = new RSA();\n\n// Generate RSA key pair, default key size is 4096 bit\nrsa.generateKeyPair(function(keyPair) {\n    // Callback function receives new key pair as a first argument\n    var publicKey = keyPair.publicKey;\n    var privateKey = keyPair.privateKey;\n});\n\n// ... or:\nrsa.generateKeyPairAsync().then(keyPair =\u003e {\n    var publicKey = keyPair.publicKey;\n    var privateKey = keyPair.privateKey;\n});\n\n// Generate 1024 bit RSA key pair\nrsa.generateKeyPair(function(keyPair) {\n    // Callback function receives new 1024 bit key pair as a first argument\n    var publicKey = keyPair.publicKey;\n    var privateKey = keyPair.privateKey;\n}, 1024); // Key size\n\n// RSA can be also initialized with options\nvar rsa = new RSA({\n    keySize: 4096,\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuhoen%2Fhybrid-crypto-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuhoen%2Fhybrid-crypto-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuhoen%2Fhybrid-crypto-js/lists"}