Skip to content

Stanwar/simplecrypto

 
 

Repository files navigation

simplecrypto for javascript

Purpose

Simple Javascript cryptography library that wraps incompatible WebCrypto implementations, utilizes encryption algorithms that all WebCrypto enabled browsers support and provides a much simpler interface.

Updates

  1. Added AES-256 as default
  2. Made config options public
  3. Added text encoding and decoding polyfills.

Supported Browsers

(Desktop and mobile versions)

  • Chrome 41+
  • Firefox 37+
  • Internet Explorer 11+
  • Safari 8.1+ (RSA signing is not available due to a WebKit bug)

Examples

Common

var data = new Uint8Array([5,4,3,2,1]);

var logError = function() {
    console.log(arguments);
}    

Symmetric

var aesKey = new Uint8Array([1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6]);
var hmacKey = new Uint8Array([1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6]);

simpleCrypto.sym.encrypt(keys, data, logError, function(encrypted) {
    simpleCrypto.sym.decrypt(keys, encrypted, logError.bind(null, done), function(decrypted) {});
});

Asymmetric

simpleCrypto.asym.generateEncryptKey(logError, function(keys){
    simpleCrypto.asym.encrypt(key.publicKey, data, logError, function(encrypted) {
        simpleCrypto.asym.decrypt(key.privateKey, encrypted, logError.bind(null, done), function(decrypted){});
    });
});
    

Please see Unit Tests for more examples

Documentation

API

FAQ

Q: Why another Javascript Crypto library?
A: Simplecrypto is built on top of WebCrypto and IndexedDB. Performance advantage over other libraries is significant. IndexedDB provides for safer storage of Javascript keys.

Q: Why AES-CBC-HMAC instead of AES-GCM?
A: WebKit does not support AES-GCM.

Q: PBKDF2?
A: Safari, IE and Chrome on Linux do not support PBKDF2, but support HMAC-SHA1.
Small shim is used to implement PBKDF2 in thise cases. Elsewhere, native PBKDF2 support is used.

License

Apache 2.0

About

Simple wrapper around WebCrypto implementations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%