├── package.json ├── LICENSE ├── README.md ├── aes4js.min.js ├── aes4js.js └── demo.html /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aes4js", 3 | "main": "aes4js.js", 4 | "version": "1.0.0", 5 | "description": "A high-level long-term-supported AES-GCM 256 encrypt/decrypt routine for JavaScript using native WebCrypto API", 6 | "keywords": [ 7 | "crypto", 8 | "AES", 9 | "WebCrypto", 10 | "browser" 11 | ], 12 | "homepage": "https://github.com/rndme/aes4js", 13 | "license": "MIT", 14 | "author": { 15 | "name": "dandavis", 16 | "email": "rndme@users.noreply.github.com", 17 | "url": "http://danml.com/" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/rndme/aes4js.git" 22 | }, 23 | "bugs": { 24 | "email": "rndme@users.noreply.github.com" 25 | }, 26 | "files": [ 27 | "aes4js.js", 28 | "aes4js.min.js" 29 | ], 30 | "npmName": "aes4js", 31 | "npmFileMap": [ 32 | { 33 | "basePath": "/", 34 | "files": [ 35 | "*.js" 36 | ] 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 dandavis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aes4js 2 | A high-level long-term-supported AES-GCM 256 encrypt/decrypt routine for JavaScript using native WebCrypto API 3 | 4 | # purpose 5 | A simple and safe promise-based text+binary encryption library for browsers. It uses plain text keys and plain-text-capable (JSON) ciphertext output for easy integration and storage. Keeping with best practices, the AES Encryption keys are derived from the plain text password using 1,000,000 rounds of PBKDF with SHA256 to prevent brute-forcing guessing. 6 | 7 | 8 | # usage 9 | There are only 2 methods: 10 | 11 | * *encrypt(key, plain)* - encode _plain_ (string or arrayBuffer) to ciphertext data object using _key_ 12 | * *decrypt(key, cipher)* - decode _cipher_ object/JSON back into _plain_(string or arrayBuffer) using _key_ 13 | 14 | # live demo 15 | See it in action on [a dead-simple encode/decode demo](https://pagedemos.com/qskd4gcdndtg/output/). 16 | 17 | # example 18 | ``` 19 | aes4js.encrypt("123", "hello world") // encrypt with password 123 20 | .then(aes4js.decrypt.bind(this, "123")) // decrypt 21 | .then(alert) // display decrypted value 22 | ``` 23 | 24 | # requires 25 | aes4js uses no outside code libraries, but does require several native browser APIs and Classes: 26 | 27 | * atob() 28 | * Array.from() 29 | * Blob() 30 | * FileReader() 31 | * TextDecoder() 32 | * TextEncoder() 33 | * Uint8Array() 34 | * crypto.getRandomValues() 35 | * crypto.subtle.encrypt() 36 | * crypto.subtle.decrypt() 37 | * crypto.subtle.digest() 38 | * crypto.subtle.exportKey() 39 | * crypto.subtle.importKey() 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /aes4js.min.js: -------------------------------------------------------------------------------- 1 | // aes4js, by dandavis. MIT applies. 2 | (function(m,f){"function"===typeof define&&define.amd?define([],f):"object"===typeof exports?module.exports=f():m.aes4js=f()})(this,function(){function m(b){return crypto.subtle.digest("SHA-256",(new TextEncoder("utf-8")).encode(b)).then(function(a){return Array.from(new Uint8Array(a)).map(function(d){return("00"+d.toString(16)).slice(-2)}).join("")})}function f(b,a){if("object"===typeof b&&b.constructor===CryptoKey)return new Promise(function(d,c){return d(b)});10>b.length&&(b=b.repeat(12-b.length)); 3 | return m("349d"+b+"9d3458694307"+b.length+String(a)).then(function(d){var c=(new TextEncoder).encode(b),e=(new TextEncoder).encode(d);return window.crypto.subtle.importKey("raw",c,{name:"PBKDF2"},!1,["deriveBits","deriveKey"]).then(function(h){return window.crypto.subtle.deriveKey({name:"PBKDF2",salt:e,iterations:1E6+b.length,hash:"SHA-256"},h,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"])})})}function n(b){var a=b.split(/[:;,]/);b=a[1];a=("base64"==a[2]?atob:decodeURIComponent)(a.pop());var d= 4 | a.length,c=0,e=new Uint8Array(d);for(c;c 2 | 3 | 4 | 5 | dan's file encrypter 6 | 10 | 11 | 12 |

dan's file encrypter

13 |

Encrypt file with 256 AES (GCM) using a PBKDF key

14 | 15 |
16 | 17 | 20 |
21 | 22 | 25 | - OR - 26 | 27 |
33 | DROP FILE HERE 34 |
35 |
36 | 73 | 74 | 75 | --------------------------------------------------------------------------------