diff --git a/README.md b/README.md index fa5c7d1..ac57c3c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ It basically encrypts your page and puts everything with a user-friendly way to AES-256 is state of the art but brute-force/dictionary attacks would be trivial to do at a really fast pace: **use a long, unusual passphrase**. -The concept is simple but I am not a cryptographer, feel free to contribute or report any thought to the GitHub project! +The concept is simple but I am not a cryptographer, feel free to contribute or report any thought to the GitHub project! (Though be warned it might take me a long time to get to it - I apologize in advance) ## CLI diff --git a/cli/index.js b/cli/index.js index e934864..222eebb 100755 --- a/cli/index.js +++ b/cli/index.js @@ -60,9 +60,37 @@ try{ process.exit(1); } +/** + * Salt and encrypt a msg with a password. + * Inspired by https://github.com/adonespitogo + */ +var keySize = 256; +var iterations = 1000; +function encrypt (msg, password) { + var salt = CryptoJS.lib.WordArray.random(128/8); + + var key = CryptoJS.PBKDF2(password, salt, { + keySize: keySize/32, + iterations: iterations + }); + + var iv = CryptoJS.lib.WordArray.random(128/8); + + var encrypted = CryptoJS.AES.encrypt(msg, key, { + iv: iv, + padding: CryptoJS.pad.Pkcs7, + mode: CryptoJS.mode.CBC + }); + + // salt, iv will be hex 32 in length + // append them to the ciphertext for use in decryption + var encryptedMsg = salt.toString()+ iv.toString() + encrypted.toString(); + return encryptedMsg; +} + // encrypt input -var encrypted = CryptoJS.AES.encrypt(contents, password); -var hmac = CryptoJS.HmacSHA256(encrypted.toString(), CryptoJS.SHA256(password).toString()).toString(); +var encrypted = encrypt(contents, password); +var hmac = CryptoJS.HmacSHA256(encrypted, CryptoJS.SHA256(password).toString()).toString(); var encryptedMessage = hmac + encrypted; // create crypto-js tag (embedded or not) diff --git a/cli/package.json b/cli/package.json index ada4535..542a09d 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "staticrypt", - "version": "1.2.0", + "version": "1.3.2", "description": "Based on the [crypto-js](https://github.com/brix/crypto-js) library, StatiCrypt uses AES-256 to encrypt your input with your passphrase and put it in a HTML file with a password prompt that can decrypted in-browser (client side).", "main": "index.js", "bin": { diff --git a/cli/password_template.html b/cli/password_template.html index 5279620..885acc5 100644 --- a/cli/password_template.html +++ b/cli/password_template.html @@ -143,6 +143,30 @@ {crypto_tag} +