Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

crypto-api-v1

nf404533MIT1.0.0

Hashing and encrypting library with no depedencies

hash, hashes, md2, md4, md5, ripemd128, ripemd160, ripemd256, ripemd320, has160, has-160, sha0, sha1, sha224, sha256, sha384, sha512, sha512/t, sha512/224, sha512/256, whirlpool, whirlpool-0, whirlpool-t, sm3, snefru, hmac

readme

Crypto API for JavaScript

Build Status Coverage Status Codacy Badge Code Climate NPM version License Type

Demo

Documentation

Features

Hashing algorithms

MAC

Encodings

Examples

Calculates SHA256 hash from UTF string "message"

import Sha256 from "crypto-api/src/hasher/sha256";
import {toHex} from "crypto-api/src/encoder/hex";
import {fromUtf} from "crypto-api/src/encoder/utf";

let hasher = new Sha256();
hasher.update(fromUtf('message'));
console.log(toHex(hasher.finalize()));

Calculates HMAC-MD5 from UTF string "message" with UTF key "key"

import Md5 from "crypto-api/src/hasher/md5";
import Hmac from "crypto-api/src/mac/hmac";
import {toHex} from "crypto-api/src/encoder/hex";
import {fromUtf} from "crypto-api/src/encoder/utf";

let hasher = new Md5();
let hmac = new Hmac(fromUtf('key'), hasher);
hmac.update(fromUtf('message'));
console.log(toHex(hmac.finalize()));

Using in browser (ES5)

Calculates SHA256 hash from string "message"

<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
  var hasher = CryptoApi.getHasher('sha256');
  hasher.update('message');
  console.log(CryptoApi.encoder.toHex(hasher.finalize()));
</script>

Calculates SHA256 hash from UTF string "message"

<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
  console.log(CryptoApi.hash('sha256', 'message'));
</script>

Calculates HMAC-MD5 from string "message" with key "key"

<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
  var hasher = CryptoApi.getHasher('md5');
  var hmac = CryptoApi.getHmac('key', hasher);
  hmac.update('message');
  console.log(CryptoApi.encoder.toHex(hmac.finalize()));
</script>

Calculates HMAC-MD5 from UTF string "message" with UTF key "key"

<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
  var hasher = CryptoApi.getHasher('md5');
  console.log(CryptoApi.hmac('key', 'message', hasher));
</script>

changelog

  • 0.8.6
    • Add file extensions to imports to support node 12
  • 0.8.5
    • This version for deployment to npm
  • 0.8.4
    • Add toBase64
    • Add fromArrayBuffer
    • Add support of SHA512/t hash
    • Optimize hash padding
    • Add SM3 hash
  • 0.8.3
    • Fix Whirlpool bug
    • Add compiled es5 version for nodejs
  • 0.8.2
    • technical version (fix npm key)
  • 0.8.1
    • Add support for nodejs
    • Refactor reset function and fix bug with constructor calling in it
    • Fix es6 usage in documentation
  • 0.8.0 Breakable changes
    • Rewrite to ES6
    • Refactor all code & invert dependencies
    • Add length option to Ripemd, Sha256, Sha512, Snefru
    • Add rounds option to Has160, Md2, Sha0, Sha1, Sha256, Sha512, Snefru, Whirlpool
    • WHIRLPOOL, WHIRLPOOL-0, WHIRLPOOL-T now selected by option type
    • Rewrite documentation to esdoc
  • 0.7.5
    • Add Snefru v2.0, Snefru v2.5
  • 0.7.4
    • Add HAS-160
    • Add WHIRLPOOL, WHIRLPOOL-0, WHIRLPOOL-T
  • 0.7.3
    • Add RIPEMD128, RIPEMD160, RIPEMD256, RIPEMD320
  • 0.7.2
    • Fix documentation
  • 0.7.1
    • Add SHA512/224, SHA512/256
  • 0.7.0
    • Add SHA384, SHA512
  • 0.6.2
    • Perfomance optimization
    • Add benchmark
  • 0.6.1
    • Add file hashing example
  • 0.6.0
    • Reorganize & refactor tests
    • Add karma & phantomjs for browser testing
    • Change coverage from jscoverage to istanbul
    • Fix require checking
    • Add autoload hash, mac & enc submodules in nodejs
    • 100% test coverage
  • 0.5.1
    • Add support getState() setState() for hashers
    • Add unit test for getState() setState()
    • Add saving state example
  • 0.5.0
    • Add MAC Api (not really good but it works)
    • Add HMAC
    • Add HMAC test vectors for MD5, SHA1, SHA224, SHA256
    • Add example for HMAC
  • Older experimental versions