0.8.5 • Published 6 years ago
crypto-api v0.8.5
Crypto API for JavaScript
Demo
- Basic hasher usage (html, js)
- File hashing on client side (html, js)
- Benchmark (html, js)
- Unit tests (html, js)
Documentation
Features
Hashing algorithms
- HAS-160
- MD2
- MD4
- MD5
- RIPEMD-160 (RIPEMD-128, RIPEMD-256, RIPEMD-320)
- SHA0
- SHA1
- SHA256 (SHA224)
- SHA512 (SHA384)
- SHA512/t (SHA512/256 SHA512/224)
- Snefru v2.0 (2 rounds 128, 4 rounds 256), Snefru v2.5 (8 rounds)
- WHIRLPOOL (WHIRLPOOL-0, WHIRLPOOL-T)
- SM3
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>
0.8.5
6 years ago
0.8.3
7 years ago
0.8.2
7 years ago
0.8.0
8 years ago
0.7.5
8 years ago
0.7.4
8 years ago
0.7.3
8 years ago
0.7.2
8 years ago
0.7.1
8 years ago
0.7.0
8 years ago
0.6.2
9 years ago
0.6.1
9 years ago
0.6.0
9 years ago
0.5.1
10 years ago
0.5.0
10 years ago
0.4.0
10 years ago
0.3.4
10 years ago
0.3.3
10 years ago
0.3.2
10 years ago
0.3.1
10 years ago
0.3.0
10 years ago
0.2.2
10 years ago
0.2.1
10 years ago
0.2.0
10 years ago
0.1.0
10 years ago