Unix crypt(3) DES-based Hash Implementation

1.1.4 · abandoned · verified Sun Apr 19

unix-crypt-td-js is a JavaScript implementation of the DES-based Unix crypt(3) password hashing algorithm, primarily based on the `crypt.c` source from the Seventh Edition Unix distribution. The package's current stable version is 1.1.4, with its last known publication to npm occurring in October 2019. Despite its historical accuracy in replicating the original Unix `crypt(3)` behavior, the underlying Data Encryption Standard (DES) algorithm is now considered cryptographically insecure. It utilizes a 56-bit key and only the first eight characters of a password, combined with a 12-bit salt, making it highly susceptible to modern brute-force attacks, dictionary attacks, and rainbow table attacks. The package is effectively unmaintained, with Snyk reporting an 'Inactive' maintenance status and limited community activity. Due to these fundamental security weaknesses and lack of ongoing development, it is unsuitable for securing sensitive data or user passwords in contemporary applications. Developers requiring secure password hashing should use modern, robust algorithms like bcrypt, scrypt, or Argon2, which are designed to resist current cryptanalytic techniques. The package has no active release cadence.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates hashing a password with a given salt, including handling byte array inputs and showing the 8-character password truncation.

const unixCryptTD = require('unix-crypt-td-js');

const password = 'mysecretpassword';
const salt = 'ab'; // In real Unix crypt(3), salt is typically 2 characters.

const hashedPassword = unixCryptTD(password, salt);
console.log(`Hashed password (string): ${hashedPassword}`); // Expected output: 'abF03p.uQ.KqE'

// Example with byte array input and byte array output
const passwordBytes = [102, 111, 111, 98]; // 'foob'
const saltBytes = [97, 114]; // 'ar'
const hashedPasswordBytes = unixCryptTD(passwordBytes, saltBytes, true);
console.log(`Hashed password (bytes): [${hashedPasswordBytes.join(', ')}]`); // Expected output: '[97, 114, 108, 69, 75, 110, 48, 79, 122, 86, 74, 110, 46]'

// Demonstrating the 8-character limit (the extra 's' is ignored)
const longPassword = 'thisisalongpassword';
const shortSalt = 'cd';
const hashedLongPassword = unixCryptTD(longPassword, shortSalt);
const hashedFirst8Chars = unixCryptTD('thisisal', shortSalt);
console.log(`Hashed long password: ${hashedLongPassword}`);
console.log(`Hashed first 8 chars: ${hashedFirst8Chars}`);
console.log(`Are they the same? ${hashedLongPassword === hashedFirst8Chars}`); // Should be true

view raw JSON →