All Projects → Caligatio → Jssha

Caligatio / Jssha

Licence: bsd-3-clause
A JavaScript/TypeScript implementation of the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Jssha

Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (-89.61%)
Mutual labels:  hash, cryptography, hmac
Securitydriven.inferno
✅ .NET crypto done right. Professionally audited.
Stars: ✭ 501 (-76.02%)
Mutual labels:  hash, cryptography, hmac
Jshashes
Fast and dependency-free cryptographic hashing library for node.js and browsers (supports MD5, SHA1, SHA256, SHA512, RIPEMD, HMAC)
Stars: ✭ 622 (-70.22%)
Mutual labels:  cryptography, hmac
Java Crypto Utils
Java Cryptographic, Encoding and Hash Utilities
Stars: ✭ 15 (-99.28%)
Mutual labels:  hash, cryptography
Merkle Tools
Tools for creating Merkle trees, generating merkle proofs, and verification of merkle proofs.
Stars: ✭ 54 (-97.42%)
Mutual labels:  hash, cryptography
Devdatatool
编码转换、摘要(hash)、加解密(MD5、SHA1、SHA256、SHA3、SM3、HMAC、DES、3DES、AES、SM4)
Stars: ✭ 446 (-78.65%)
Mutual labels:  hash, hmac
Bitcracker
BitCracker is the first open source password cracking tool for memory units encrypted with BitLocker
Stars: ✭ 463 (-77.84%)
Mutual labels:  hash, cryptography
Practical Cryptography For Developers Book
Practical Cryptography for Developers: Hashes, MAC, Key Derivation, DHKE, Symmetric and Asymmetric Ciphers, Public Key Cryptosystems, RSA, Elliptic Curves, ECC, secp256k1, ECDH, ECIES, Digital Signatures, ECDSA, EdDSA
Stars: ✭ 2,400 (+14.89%)
Mutual labels:  cryptography, hmac
hash-wasm
Lightning fast hash functions using hand-tuned WebAssembly binaries
Stars: ✭ 382 (-81.71%)
Mutual labels:  hash, hmac
Siphash Js
A Javascript implementation of SipHash-2-4
Stars: ✭ 90 (-95.69%)
Mutual labels:  hash, cryptography
Beamsplitter
💎 Beamsplitter - A new (possibly universal) hash that passes SMHasher. Built mainly with a random 10x64 S-box. Also in NodeJS
Stars: ✭ 83 (-96.03%)
Mutual labels:  hash, cryptography
Node Sha3
SHA3 for JavaScript - The Keccak family of hash algorithms
Stars: ✭ 112 (-94.64%)
Mutual labels:  hash, cryptography
Chronicle
Public append-only ledger microservice built with Slim Framework
Stars: ✭ 429 (-79.46%)
Mutual labels:  hash, cryptography
Forge
A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
Stars: ✭ 4,204 (+101.24%)
Mutual labels:  cryptography, hmac
crypthash-net
CryptHash.NET is a .NET multi-target library to encrypt/decrypt/hash/encode/decode strings and files, with an optional .NET Core multiplatform console utility.
Stars: ✭ 33 (-98.42%)
Mutual labels:  hash, hmac
Cl Tls
An implementation of TLS and related specifications in Common Lisp
Stars: ✭ 32 (-98.47%)
Mutual labels:  cryptography, hmac
Crypto Async
Fast, reliable cipher, hash and hmac methods executed in Node's threadpool for multi-core throughput.
Stars: ✭ 161 (-92.29%)
Mutual labels:  hash, hmac
ngx http hmac secure link module
HMAC Secure Link module for NGINX.
Stars: ✭ 47 (-97.75%)
Mutual labels:  hash, hmac
simple-sha256
Generate SHA-256 hashes (in Node and the Browser)
Stars: ✭ 42 (-97.99%)
Mutual labels:  hash, sha-256
Cryptoswift
CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift
Stars: ✭ 8,846 (+323.46%)
Mutual labels:  cryptography, hmac

jsSHA

A pure TypeScript/JavaScript streaming implementation of the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC.

npm Build Status Coverage Status NPM

Usage

More complete documentation can be found on the jsSHA Wiki but below are common use-cases.

Installation

Browser

Include the desired JavaScript file (sha.js, sha1.js, sha256.js, sha512.js, or sha3.js) in your header:

<script type="text/javascript" src="/path/to/sha.js"></script>

Node.js

jsSHA is available through NPM and be installed by simply doing

npm install jssha

To use the module, first require it using:

const jsSHA = require("jssha");
/* The limited variant files are also exported (sha1, sha256, sha512, and sha3)
 * using conditional subpath exports in Node.js v13+ or using --experimental-modules
 * in v12 */
const jsSHA1 = require("jssha/sha1");
/* For Node.js versions that don't support subpath exports, you can do the
 * following instead: */
const jsSHA1 = require("jssha/dist/sha1");
/* Alternatively, you can load it as an ESM (Node.js v13+ or using
 * --experimental-modules in v12) */
import jsSHA from "jssha";

Hashing

Instantiate a new jsSHA object with the desired hash variant, input format, and options as parameters. The hash variant can be one of SHA-1, SHA-224, SHA3-224, SHA-256, SHA3-256, SHA-384, SHA3-384, SHA-512, SHA3-512, SHAKE128, or SHAKE256. The input format can be one of HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY. You can then stream in input using the update object function, calling it multiple times if needed. Finally, simply call getHash with the output type as a parameter (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY). Example to calculate the SHA-512 of "This is a test":

const shaObj = new jsSHA("SHA-512", "TEXT", { encoding: "UTF8" });
shaObj.update("This is a ");
shaObj.update("test");
const hash = shaObj.getHash("HEX");

The constructor takes a hashmap as a optional third argument with defaults {"encoding" : "UTF8", "numRounds" : 1}. numRounds controls the number of hashing iterations/rounds performed and encoding specifies the encoding used to encode TEXT-type inputs. Valid encoding values are "UTF8", "UTF16BE", and "UTF16LE".

getHash also takes a hashmap as an optional second argument with defaults {"outputUpper" : false, "b64Pad" : "="}. outputUpper is only used for "HEX" outputs and b64Pad only for "B64" outputs.

Important: SHAKE128 and SHAKE256 require outputLen to be in the hashmap where outputLen is the desired output length of the SHAKE algorithm in a multiple of 8 bits.

HMAC

Instantiate a new jsSHA object similiar to hashing but with the third argument in the form of { "hmacKey": { "value": VALUE, "format": FORMAT } }. FORMAT takes the same values as the input format from hashing and the VALUE is then either a string, ArrayBuffer, or Uint8Array. You can stream in the input using the update object function just like hashing. Finally, get the HMAC by calling the getHash function with the output type as its argument. Example to calculate the SHA-512 HMAC of the string "This is a test" with the key "abc":

const shaObj = new jsSHA("SHA-512", "TEXT", {
  hmacKey: { value: "abc", format: "TEXT" },
});
shaObj.update("This is a ");
shaObj.update("test");
const hmac = shaObj.getHash("HEX");

Note: You cannot specify numRounds with HMAC.

cSHAKE

Instantiate a new jsSHA object similiar to HMAC but first argument being either "CSHAKE128" or "CSHAKE256" and the third argument in the form of { "customization"?: { "value": VALUE, "format": FORMAT }, "funcName"?: { "value": VALUE, "format": FORMAT } }. FORMAT takes the same values as the input format from hashing and the VALUE is then either a string, ArrayBuffer, or Uint8Array. Per the NIST specification, both customization and funcName are optional. You can stream in the input using the update object function just like hashing. Finally, get the hash by calling the getHash function with the output type and length as arguments. Example to calculate the cSHAKE128 of the string "This is a test" with the customization string "My Tagged Application" and an output size of 256-bits.

const shaObj = new jsSHA("CSHAKE128", "TEXT", {
  customization: { value: "My Tagged Application", format: "TEXT" },
});
shaObj.update("This is a ");
shaObj.update("test");
const cshake = shaObj.getHash("HEX", { outputLen: 256 });

Note: You cannot specify numRounds with cSHAKE.

Important: outputLen is required to be in the hashmap where outputLen is the desired output length of the cSHAKE algorithm in a multiple of 8 bits.

KMAC

Instantiate a new jsSHA object similiar to cSHAKE but first argument being either "KMAC128" or "KMAC256" and the third argument in the form of { "customization"?: { "value": VALUE, "format": FORMAT }, "kmacKey?: { "value": VALUE, "format": FORMAT } }. FORMAT takes the same values as the input format from hashing and the VALUE is then either a string, ArrayBuffer, or Uint8Array. Per the NIST specification customization is optional whereas kmacKey is required. You can stream in the input using the update object function just like hashing. Finally, get the hash by calling the getHash function with the output type and length as arguments. Example to calculate the KMAC128 of the string "This is a test" with the customization string "My Tagged Application", key "abc", and an output size of 256-bits.

const shaObj = new jsSHA("KMAC128", "TEXT", {
  customization: { value: "My Tagged Application", format: "TEXT" },
  kmacKey: { value: "abc", format: "TEXT" },
});
shaObj.update("This is a ");
shaObj.update("test");
const kmac = shaObj.getHash("HEX", { outputLen: 256 });

Note: You cannot specify numRounds with KMAC.

Important: outputLen is required to be in the hashmap where outputLen is the desired output length of the KMAC algorithm in a multiple of 8 bits.

Files

  • dist/sha.js - The minified ECMAScript 3 (ES3) compatible Universal Module Definition (UMD) version of the library with support for all hash variants. Its accompanying source map can be found in dist/sha.js.map and its TypeScript declarations in dist/sha.d.ts.
  • dist/sha.mjs - The minified ECMAScript 2015 (ES6) compatible ESM version of the library with support for all hash variants. Its accompanying source map can be found in dist/sha.mjs.map and its TypeScript declarations in dist/sha.d.ts.
  • dist/sha1.{js,mjs} - The minified UMD and ESM versions of the library with support for only the SHA-1 hash variant. Its accompanying TypeScript declarations can be found in dist/sha1.d.ts.
  • dist/sha256.{js,mjs} - The minified UMD and ESM versions of the library with support for only the SHA-224 and SHA-256 hash variants. Its accompanying TypeScript declarations can be found in dist/sha256.d.ts.
  • dist/sha512.{js,mjs} - The minified UMD and ESM versions of the library with support for only the SHA-384 and SHA-512 hash variants. Its accompanying TypeScript declarations can be found in dist/sha513.d.ts.
  • dist/sha3.{js,mjs} - The minified UMD and ESM versions of the library with support for only the SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128, SHAKE256, cSHAKE128, cSHAKE256, KMAC128, and KMAC256 hash variants. Its accompanying TypeScript declarations can be found in dist/sha3.d.ts.

Contact Info

The project's website is located at https://caligatio.github.com/jsSHA/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].