Code Monkey home page Code Monkey logo

crypto-api's Introduction

Crypto API for JavaScript

Build Status Coverage Status Codacy Badge Code Climate bitHound Overalll Score NPM version License Type

Demo

Features

Hashing algorithms

MAC

Encodings

Examples

ES6 (recomended)

Calculates SHA256 hash from UTF string "message"

import Sha256 from "crypto-api/hasher/sha256";
import {toHex} from "crypto-api/encoder/hex";
import {fromUtf} from "crypto-api/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/hasher/md5";
import Hmac from "crypto-api/mac/hmac";
import {toHex} from "crypto-api/encoder/hex";
import {fromUtf} from "crypto-api/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>

crypto-api's People

Contributors

nf404 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.