CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-crypto-js

JavaScript library of crypto standards providing comprehensive cryptographic algorithms including hashing, encryption, HMAC, and encoding utilities.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

hash-functions.mddocs/

Hash Functions

Cryptographic hash functions for data integrity, digital signatures, and secure data verification. All hash functions in CryptoJS follow a consistent pattern: they accept string or WordArray input and return a WordArray that can be converted to various string formats.

Capabilities

MD5 Hash Function

MD5 hash algorithm (not recommended for security-critical applications due to vulnerabilities).

/**
 * Computes MD5 hash of the input message
 * @param message - String or WordArray to hash
 * @returns WordArray containing the hash
 */
CryptoJS.MD5(message)

Usage Example:

var CryptoJS = require("crypto-js");

var hash = CryptoJS.MD5("Hello World");
console.log(hash.toString()); // "b10a8db164e0754105b7a99be72e3fe5"
console.log(hash.toString(CryptoJS.enc.Base64)); // "sQqNsWTgdUEFt6mb5y4/5Q=="

SHA-1 Hash Function

SHA-1 hash algorithm (deprecated for security-critical applications).

/**
 * Computes SHA-1 hash of the input message
 * @param message - String or WordArray to hash
 * @returns WordArray containing the hash
 */
CryptoJS.SHA1(message)

SHA-224 Hash Function

SHA-224 hash algorithm, producing 224-bit hash values.

/**
 * Computes SHA-224 hash of the input message
 * @param message - String or WordArray to hash
 * @returns WordArray containing the hash
 */
CryptoJS.SHA224(message)

SHA-256 Hash Function

SHA-256 hash algorithm, producing 256-bit hash values. Recommended for most applications.

/**
 * Computes SHA-256 hash of the input message
 * @param message - String or WordArray to hash
 * @returns WordArray containing the hash
 */
CryptoJS.SHA256(message)

Usage Example:

var CryptoJS = require("crypto-js");

var hash = CryptoJS.SHA256("Hello World");
console.log(hash.toString()); // "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"

// Hash WordArray data
var data = CryptoJS.enc.Utf8.parse("Hello World");
var hash2 = CryptoJS.SHA256(data);
console.log(hash2.toString() === hash.toString()); // true

SHA-384 Hash Function

SHA-384 hash algorithm, producing 384-bit hash values.

/**
 * Computes SHA-384 hash of the input message
 * @param message - String or WordArray to hash
 * @returns WordArray containing the hash
 */
CryptoJS.SHA384(message)

SHA-512 Hash Function

SHA-512 hash algorithm, producing 512-bit hash values.

/**
 * Computes SHA-512 hash of the input message
 * @param message - String or WordArray to hash
 * @returns WordArray containing the hash
 */
CryptoJS.SHA512(message)

SHA-3 Hash Function

SHA-3 (Keccak) hash algorithm with configurable output length.

/**
 * Computes SHA-3 hash of the input message
 * @param message - String or WordArray to hash
 * @param cfg - Configuration object with optional outputLength
 * @returns WordArray containing the hash
 */
CryptoJS.SHA3(message, cfg)

Usage Example:

var CryptoJS = require("crypto-js");

// Default SHA-3 (512-bit output)
var hash = CryptoJS.SHA3("Hello World");
console.log(hash.toString());

// SHA-3 with custom output length
var hash224 = CryptoJS.SHA3("Hello World", { outputLength: 224 });
var hash256 = CryptoJS.SHA3("Hello World", { outputLength: 256 });
var hash384 = CryptoJS.SHA3("Hello World", { outputLength: 384 });
var hash512 = CryptoJS.SHA3("Hello World", { outputLength: 512 });

RIPEMD-160 Hash Function

RIPEMD-160 hash algorithm, producing 160-bit hash values.

/**
 * Computes RIPEMD-160 hash of the input message
 * @param message - String or WordArray to hash
 * @returns WordArray containing the hash
 */
CryptoJS.RIPEMD160(message)

Common Patterns

Hash with Different Output Formats

var CryptoJS = require("crypto-js");

var message = "Hello World";
var hash = CryptoJS.SHA256(message);

// Different output formats
console.log("Hex:", hash.toString());                           // Default hex
console.log("Base64:", hash.toString(CryptoJS.enc.Base64));    // Base64
console.log("Words:", hash.words);                             // Raw word array
console.log("Bytes:", hash.sigBytes);                          // Significant bytes count

Progressive Hashing

var CryptoJS = require("crypto-js");

// Create hasher instance for progressive hashing
var sha256 = CryptoJS.algo.SHA256.create();
sha256.update("Hello");
sha256.update(" ");
sha256.update("World");
var hash = sha256.finalize();

console.log(hash.toString()); // Same result as CryptoJS.SHA256("Hello World")

File Hashing Pattern

var CryptoJS = require("crypto-js");
var fs = require("fs");

function hashFile(filePath) {
    var data = fs.readFileSync(filePath, 'utf8');
    return CryptoJS.SHA256(data).toString();
}

// Usage
var fileHash = hashFile("./document.txt");
console.log("File SHA-256:", fileHash);

Types

// Hash Configuration (for SHA-3)
HasherCfg {
  outputLength?: number;  // Output length in bits (224, 256, 384, 512)
}

// Hash Algorithm Interface
Hasher {
  update(messageUpdate): Hasher;     // Add data to hash
  finalize(messageUpdate?): WordArray; // Compute final hash
  reset(): void;                     // Reset hasher state
  clone(): Hasher;                   // Clone hasher instance
}

Install with Tessl CLI

npx tessl i tessl/npm-crypto-js

docs

cipher-config.md

encoding.md

encryption.md

hash-functions.md

hmac.md

index.md

key-derivation.md

tile.json