Log In

crypto

ModuleIsomorphic

Cryptographic functions

Documentation

cryptomd5HashFunctionsha1HashFunctionsha256HashFunctionhmackeyArrayBufferdatanullArrayBufferalgorithm`crypto.sha256`HashFunctionArrayBufferdataArrayBufferArrayBufferpbkdf2passwordArrayBuffersaltArrayBufferiterations1000numberArrayBuffer

Cryptographic functions. hmac returns an ArrayBuffer MAC if data is provided up front, or a MAC generator function otherwise.

Consider using native crypto.subtle functions (which operate asynchronously using Promises) instead of this module for secure crypto primitives:

// hash (MD5 not supported):
crypto.subtle.digest('sha-256', data);
// hmac:
crypto.subtle.importKey('raw', key, {name: 'hmac', hash: 'sha-256'}, false, ['sign']).then(function(key) {
  return crypto.subtle.sign({name: 'hmac', hash: 'sha-256'}, key, data);
});
// pbkdf2:
crypto.subtle.importKey('raw', password, 'pbkdf2', false, ['deriveKey']).then(function(key) {
  return crypto.subtle.deriveKey({name: 'pbkdf2', salt: salt, iterations: iterations, hash: 'sha-256'},
    key, {name: 'aes-cbc', length: 256}, true, ['encrypt']);
}).then(function(key) {
  return crypto.subtle.exportKey('raw', key);
});
HashFunctiondataundefinedArrayBufferArrayBufferMessageDigest

A hash function returns an ArrayBuffer hash if data is provided up front, or a MessageDigest object otherwise.

MessageDigestupdatedataArrayBufferMessageDigestdigestArrayBuffer