Hashing and encrypting library with no depedencies


Keywords
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
License
MIT
Install
npm install crypto-api@0.8.5

Documentation

Crypto API for JavaScript

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

Demo

Documentation

Features

Hashing algorithms

MAC

Encodings

Examples

ES6 (recommended)

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>