Skip to content
/ aes4js Public

A high-level AES-GCM 256 encrypt/decrypt routine for JavaScript using native WebCrypto API

License

Notifications You must be signed in to change notification settings

rndme/aes4js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aes4js

A high-level long-term-supported AES-GCM 256 encrypt/decrypt routine for JavaScript using native WebCrypto API

purpose

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.

usage

There are only 2 methods:

  • encrypt(key, plain) - encode plain (string or arrayBuffer) to ciphertext data object using key
  • decrypt(key, cipher) - decode cipher object/JSON back into plain(string or arrayBuffer) using key

live demo

See it in action on a dead-simple encode/decode demo.

example

aes4js.encrypt("123", "hello world") // encrypt with password 123
      .then(aes4js.decrypt.bind(this, "123")) // decrypt
      .then(alert) // display decrypted value

requires

aes4js uses no outside code libraries, but does require several native browser APIs and Classes:

  • atob()
  • Array.from()
  • Blob()
  • FileReader()
  • TextDecoder()
  • TextEncoder()
  • Uint8Array()
  • crypto.getRandomValues()
  • crypto.subtle.encrypt()
  • crypto.subtle.decrypt()
  • crypto.subtle.digest()
  • crypto.subtle.exportKey()
  • crypto.subtle.importKey()

About

A high-level AES-GCM 256 encrypt/decrypt routine for JavaScript using native WebCrypto API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published