⚡️🔐 QuickEncrypt
Easily generate RSA Public-Private Keypairs and use them for secure asymmetric one-way encryption and decryption!
Installation
npm install quick-encrypt
Usage
Add this to the js file that you are using it in:
let QuickEncrypt =
Generating a RSA Public-Private Keypair:
let keys = QuickEncrypt // Use either 2048 bits or 1024 bits. console // Public Key that has been generated. console // Private Key that has been generated.
Encrypting a secret payload:
let publicKey = keyspublic // " -----BEGIN RSA PUBLIC KEY-----\nMIGJAoGBAIXlXZs+0FoIGBc5pjnZZxtvIzdDFtNi3SVi6vf2J...... " let encryptedText = QuickEncrypt console // Some encrypted text: " 01c066e00c660aabadfc320621d9c3ac25ccf2e4c29e8bf4c...... "
Decrypting a secret payload:
let privateKey = keysprivate // " -----BEGIN RSA PRIVATE KEY-----\nMIICWwIBAAKBgQCF5V2bPtBaCBgXOaY52WcbbyM3QxbTYt0lYur..... " let decryptedText = QuickEncrypt console // The decrypted text: "This is some super top secret text!"
Full Example:
const QuickEncrypt = // --- RSA Keypair Generation ---let keys = QuickEncrypt // Use either 2048 bits or 1024 bits.console // Generated Public Key and Private Key pairlet publicKey = keyspubliclet privateKey = keysprivate // --- Encrypt using public key ---let encryptedText = QuickEncryptconsole // This will print out the ENCRYPTED text, for example : " 01c066e00c660aabadfc320621d9c3ac25ccf2e4c29e8bf4c...... " // --- Decrypt using private key ---let decryptedText = QuickEncryptconsole // This will print out the DECRYPTED text, which is " This is some super top secret text! "
Tests
npm test
Contributing
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.