{"_id":"@arthurcortezz/hybrid-crypto-js","name":"@arthurcortezz/hybrid-crypto-js","dist-tags":{"latest":"0.2.4"},"versions":{"0.2.4":{"name":"@arthurcortezz/hybrid-crypto-js","version":"0.2.4","description":"Hybrid (RSA+AES) encryption and decryption toolkit for JavaScript","main":"lib/index.js","scripts":{"prepublish":"npm run build","webpack":"browserify lib/webpack.js -o web/hybrid-crypto.js","uglify":"uglifyjs web/hybrid-crypto.js -o web/hybrid-crypto.min.js","flow":"flow","babel":"babel src/ -d lib/","build":"npm run babel && npm run webpack && npm run uglify","test":"npm run babel && mocha -R spec"},"repository":{"type":"git","url":"git+https://github.com/arthurcortezz/hybrid-crypto-js.git"},"keywords":["rsa","aes","rsa+aes","react","node","react-native"],"author":{"name":"Juho Enala","email":"juho.enala@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/arthurcortezz/hybrid-crypto-js/issues"},"homepage":"https://github.com/arthurcortezz/hybrid-crypto-js","dependencies":{"node-forge":"^0.8.5"},"devDependencies":{"@babel/cli":"^7.5.5","@babel/core":"^7.5.5","@babel/preset-env":"^7.5.5","@babel/preset-flow":"^7.0.0","babel-core":"^6.26.0","babel-preset-env":"1.6.0","babel-preset-es2015":"^6.24.1","babelify":"^8.0.0","browserify":"^16.5.0","chai":"^4.1.2","flow-bin":"^0.107.0","mocha":"^4.0.1","prettier":"^1.18.2","uglify-js":"^3.2.1"},"browserslist":"> 0.25%, not dead","gitHead":"a87baf4dab7ef6e40507570cc96110282ba1c3fd","_id":"@arthurcortezz/hybrid-crypto-js@0.2.4","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-AYgvbQKb0XZFSPoUNW1E3IxYcF1e4Z4LIcTikKIBg7ZesOnmUOkfHrVaOBzn5rsu7sCOtTeHUNFEDhLX1jUq7g==","shasum":"f22ef106943fa4df901e45843c2cd501f8ebebb5","tarball":"https://registry.npmjs.org/@arthurcortezz/hybrid-crypto-js/-/hybrid-crypto-js-0.2.4.tgz","fileCount":22,"unpackedSize":1382073,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE0I6dflnV8Hr8Pn7Tqtcx9yGlYXSQ/Ich+1g2r8BhtlAiBLqCSNfMjIu4f92a0ULuOEWapt/OoZ8qda3iHjJUepQg=="}]},"_npmUser":{"name":"arthurcortezz","email":"arthurcortez2@gmail.com"},"directories":{},"maintainers":[{"name":"arthurcortezz","email":"arthurcortez2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hybrid-crypto-js_0.2.4_1691599947972_0.7079001149295867"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-09T16:52:27.833Z","0.2.4":"2023-08-09T16:52:28.219Z","modified":"2023-08-09T16:52:28.495Z"},"maintainers":[{"name":"arthurcortezz","email":"arthurcortez2@gmail.com"}],"description":"Hybrid (RSA+AES) encryption and decryption toolkit for JavaScript","homepage":"https://github.com/arthurcortezz/hybrid-crypto-js","keywords":["rsa","aes","rsa+aes","react","node","react-native"],"repository":{"type":"git","url":"git+https://github.com/arthurcortezz/hybrid-crypto-js.git"},"author":{"name":"Juho Enala","email":"juho.enala@gmail.com"},"bugs":{"url":"https://github.com/arthurcortezz/hybrid-crypto-js/issues"},"license":"MIT","readme":"# Hybrid Crypto JS\r\n\r\n[![NPM](https://nodei.co/npm/hybrid-crypto-js.png)](https://nodei.co/npm/hybrid-crypto-js/)\r\n\r\n## Introduction\r\n\r\n<a name=\"introduction\"></a>\r\n\r\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.\r\n\r\n## Documentation\r\n\r\n<a name=\"documentation\"></a>\r\n\r\n**Getting started**\r\n\r\n-   [Introduction](#introduction)\r\n-   [Documentation](#documentation)\r\n-   [Installation](#installation)\r\n\r\n**Features**\r\n\r\n-   [Initialization](#initialization)\r\n-   [Encryption](#encryption)\r\n-   [Decryption](#decryption)\r\n-   [Signatures](#signatures)\r\n-   [Verifying](#verifying)\r\n-   [RSA key pairs](#rsa-key-pairs)\r\n\r\n### Installation\r\n\r\n<a name=\"installation\"></a>\r\n\r\n```\r\nnpm install hybrid-crypto-js\r\n```\r\n\r\n### Importing\r\n\r\n**Node.js**\r\n\r\n```js\r\nvar RSA = require('hybrid-crypto-js').RSA;\r\nvar Crypt = require('hybrid-crypto-js').Crypt;\r\n```\r\n\r\n**React Native**\r\n\r\n```js\r\nimport { Crypt, RSA } from 'hybrid-crypto-js';\r\n```\r\n\r\n**Web**\r\n\r\nDownload minified _hybrid-crypto.min.js_ file [here](https://raw.githubusercontent.com/juhoen/hybrid-crypto-js/master/web/hybrid-crypto.min.js).\r\n\r\n```html\r\n<script type=\"text/javascript\" src=\"hybrid-crypto.min.js\"></script>\r\n```\r\n\r\n## Features\r\n\r\n### Initialization\r\n\r\n<a name=\"initialization\"></a>\r\n\r\n```js\r\n// Basic initialization\r\nvar crypt = new Crypt();\r\nvar rsa = new RSA();\r\n\r\n// Increase amount of entropy\r\nvar entropy = 'Random string, integer or float';\r\nvar crypt = new Crypt({ entropy: entropy });\r\nvar rsa = new RSA({ entropy: entropy });\r\n\r\n// Select default message digest\r\nvar crypt = new Crypt({ md: 'sha512' });\r\n\r\n// Select AES or RSA standard\r\nvar crypt = new Crypt({\r\n    // Default AES standard is AES-CBC. Options are:\r\n    // AES-ECB, AES-CBC, AES-CFB, AES-OFB, AES-CTR, AES-GCM, 3DES-ECB, 3DES-CBC, DES-ECB, DES-CBC\r\n    aesStandard: 'AES-CBC',\r\n    // Default RSA standard is RSA-OAEP. Options are:\r\n    // RSA-OAEP, RSAES-PKCS1-V1_5\r\n    rsaStandard: 'RSA-OAEP',\r\n});\r\n\r\n// Alternate AES keysize (some AES algorithms requires specific key size)\r\nvar crypt = new Crypt({\r\n    aesKeySize: 192, // Defaults to 256\r\n});\r\n```\r\n\r\n### Encryption\r\n\r\n<a name=\"encryption\"></a>\r\n\r\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.\r\n\r\n```js\r\nvar message = 'Hello world!';\r\n\r\n// Encryption with one public RSA key\r\nvar encrypted = crypt.encrypt(publicKey, message);\r\n\r\n// Function also supports encryption with multiple RSA public keys\r\nvar encrypted = crypt.encrypt([publicKey1, publicKey2, publicKey3], message);\r\n\r\n// Encryption with signature\r\nvar encrypted = crypt.encrypt(publicKey, message, signature);\r\n```\r\n\r\n**Pretty-printed sample output**\r\n\r\n```js\r\n{\r\n    \"v\": \"hybrid-crypto-js_0.1.2\",        // Current package version\r\n    \"iv\": \"CmtyaZTyzoAp1mTNUTztic0v1...\", // Initialization vector\r\n    \"keys\": {                             // Encrypted AES keys by RSA fingerprints\r\n        \"85:3d:10:e1:56...\": \"bHaTF9...\",\r\n        \"d3:48:6a:e9:13...\": \"t9eds3...\"\r\n    },\r\n    \"cipher\": \"+iwVFsC2dECBQvwcm9DND...\"  // Actual encrypted message\r\n    \"signature\": \"sdL93kfdm12feds3C2...\"  // Signature (optional)\r\n}\r\n\r\n```\r\n\r\n### Decryption\r\n\r\n<a name=\"decryption\"></a>\r\n\r\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.\r\n\r\n```js\r\nvar encrypted = '{\"v\":\"hybrid-crypto-js_0.1.0\",\"iv\":\"CmtyaZTyzoAp1mTN...';\r\n\r\n// Decrypt encryped message with private RSA key\r\nvar decrypted = crypt.decrypt(privateKey, encrypted);\r\n\r\n// Get decrypted message\r\nvar message = decrypted.message;\r\n```\r\n\r\n**Sample output**\r\n\r\n```js\r\n{\r\n    message: \"Hello world!\",            // Actual decrypted message\r\n    signature: \"sdL93kfdm12feds3C2...\"  // Signature (optional)\r\n}\r\n```\r\n\r\n### Signatures\r\n\r\n<a name=\"signatures\"></a>\r\n\r\n_Hybrid Crypto JS_ provides simple message signing. The encrypted message can be signed with the issuer's private key.\r\n\r\n```js\r\nvar message = 'Hello world!';\r\n\r\n// Create a signature with ISSUER's private RSA key\r\nvar signature = crypt.signature(issuerPrivateKey, message);\r\n\r\n// Encrypt message with RECEIVERS public RSA key and attach the signature\r\nvar encrypted = crypt.encrypt(receiverPublicKey, message, signature);\r\n\r\n// Select default message digest\r\nvar crypt = new Crypt({\r\n    md: 'sha512', // Options: sha1, sha256, sha384, sha512, and md5\r\n});\r\n```\r\n\r\n### Verifying\r\n\r\n<a name=\"verifying\"></a>\r\n\r\nThe message receiver needs to have a message issuer's public RSA key in order to verify the message issuer.\r\n\r\n```js\r\n// Encrypted message with signature\r\nvar encrypted = '{\"v\":\"hybri... ...\"signature\":\"sdL93kfd...';\r\n\r\n// Decrypt message with own (RECEIVER) private key\r\nvar decrypted = crypt.decrypt(receiverPrivateKey, encrypted);\r\n\r\n// Verify message with ISSUER's public key\r\nvar verified = crypt.verify(\r\n    issuerPublicKey,\r\n    decrypted.signature,\r\n    decrypted.message,\r\n);\r\n```\r\n\r\nVerification function returns _true_ or _false_ depending on whether the verification was successful.\r\n\r\n### RSA key pairs\r\n\r\n<a name=\"rsa-key-pairs\"></a>\r\n\r\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.\r\n\r\n```js\r\n// Initialize RSA-class\r\nvar rsa = new RSA();\r\n\r\n// Generate RSA key pair, default key size is 4096 bit\r\nrsa.generateKeyPair(function(keyPair) {\r\n    // Callback function receives new key pair as a first argument\r\n    var publicKey = keyPair.publicKey;\r\n    var privateKey = keyPair.privateKey;\r\n});\r\n\r\n// ... or:\r\nrsa.generateKeyPairAsync().then(keyPair => {\r\n    var publicKey = keyPair.publicKey;\r\n    var privateKey = keyPair.privateKey;\r\n});\r\n\r\n// Generate 1024 bit RSA key pair\r\nrsa.generateKeyPair(function(keyPair) {\r\n    // Callback function receives new 1024 bit key pair as a first argument\r\n    var publicKey = keyPair.publicKey;\r\n    var privateKey = keyPair.privateKey;\r\n}, 1024); // Key size\r\n\r\n// RSA can be also initialized with options\r\nvar rsa = new RSA({\r\n    keySize: 4096,\r\n});\r\n```\r\n","readmeFilename":"README.md"}