Package Exports
- js-crypto-aes
- js-crypto-aes/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (js-crypto-aes) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Universal Module for AES Encryption and Decryption in JavaScript
WARNING: At this time this solution should be considered suitable for research and experimentation, further code and security review is needed before utilization in a production application.
Introduction and Overview
This library is designed to be 'universal' as an AES function, i.e., it works both on most browsers and on Node.js just by importing from npm/source code. Note that in the design principle, the library fully utilizes native APIs like WebCrypto API to accelerate its operation if available.
Installation
At your project directory, do either one of the following.
- From npm/yarn:
$ npm install --save js-crypto-aes // npm $ yarn add js-crypto-aes // yarn
- From GitHub:
$ git clone https://github.com/junkurihara/js-crypto-aes.git
Then you should import the package as follows.
import aes from 'js-crypto-aes'; // for npm
import aes from 'js-crypto-aes/dist/index.js'; // for githubUsage
Encryption in AES-GCM
const msg = ...; // arbitrary length of message in Uint8Array
const key = ...; // 16 bytes or 32 bytes key in Uint8Array
const iv = ...; // 12 bytes IV in Uint8Array for AES-GCM mode
aes.encrypt(msg, key, {name: 'AES-GCM', iv, tagLength: 16}).then( (encrypted) => {
// now you get an Uint8Array of encrypted message
});Decryption in AES-GCM
const data = ...; // encryted message in Uint8Array
const key = ...; // 16 bytes or 32 bytes key in Uint8Array
const iv = ...; // 12 bytes IV in Uint8Array for AES-GCM mode that is exactly same as the one used in encryption
aes.decrypt(data, key, {name: 'AES-GCM', iv, tagLength: 16}).then( (decrypted) => {
// now you get an Uint8Array of decrypted message
});Note
At this point, this module has the following limitations:
- Supports only AES-GCM mode
- Supports 128 bits and 256 bits keys in Chrome (192 bits key works in Node.js)
- May not work in legacy IE11
License
Licensed under the MIT license, see LICENSE file.