What is cryptiles?
The cryptiles package is a utility library that provides various cryptographic functions. It is part of the hapi ecosystem and is designed to make certain security-related tasks easier for developers.
What are cryptiles's main functionalities?
Random String Generation
Generates a cryptographically strong random string. The argument specifies the length of the string.
const Cryptiles = require('cryptiles');
const randomString = Cryptiles.randomString(32);
Fixed Time String Comparison
Compares two strings in constant time to prevent timing attacks. It returns true if the strings are equal, false otherwise.
const Cryptiles = require('cryptiles');
const a = 'some string';
const b = 'some string';
const comparisonResult = Cryptiles.fixedTimeComparison(a, b);
Other packages similar to cryptiles
crypto
The built-in Node.js 'crypto' module provides a wide range of cryptographic functions, including random string generation and secure hashing. It is more comprehensive than cryptiles but also more complex to use.
bcryptjs
bcryptjs is a package for hashing passwords using the bcrypt algorithm. It is similar to cryptiles in providing cryptographic functions but is specifically focused on password hashing and salting.
randombytes
randombytes is a simple package that allows you to generate cryptographically strong random bytes. It is similar to the random string generation feature of cryptiles but does not include other cryptographic utilities.
cryptiles
General purpose crypto utilities
Lead Maintainer - C J Silverio
Methods
randomString(<Number> size)
Returns a cryptographically strong pseudo-random data string. Takes a size argument for the length of the string.
randomDigits(<Number> size)
Returns a cryptographically strong pseudo-random data string consisting of only numerical digits (0-9). Takes a size argument for the length of the string.
fixedTimeComparison(<String> a, <String> b)
Compare two strings using fixed time algorithm (to prevent time-based analysis of MAC digest match). Returns true
if the strings match, false
if they differ.