Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get available hash algorithms in nodejs crypto module

I'd like to know if there is a way (API method for example) to know all available hash algorithms (and the exact input name) in NodeJs crypto module.

According to official docs, in createHash function it is said:

https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options

The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms (openssl list-message-digest-algorithms for older versions of OpenSSL) will display the available digest algorithms.

So depending the OpenSSL version in the node version I am running, I will have different hash algorithm options? Any way(like API method) to know available hash algorithms in the installed crypto module directly?

Thanks

like image 904
AlexAcc Avatar asked Oct 19 '25 11:10

AlexAcc


1 Answers

Node's crypto has an api for getHashes() according to their documentation.

Sample list

let crypto = require('crypto');
let listOfSupportedHashes = crypto.getHashes();
console.log('Total supported hashes : ', listOfSupportedHashes.length);
like image 51
Sudheesh Singanamalla Avatar answered Oct 21 '25 02:10

Sudheesh Singanamalla