Skip to content

Instantly share code, notes, and snippets.

@ryanhs
Created March 11, 2023 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanhs/878bf9331e93ba6654a221ce3bbc03e5 to your computer and use it in GitHub Desktop.
Save ryanhs/878bf9331e93ba6654a221ce3bbc03e5 to your computer and use it in GitHub Desktop.
nodejs hashes compare
// using node v16.19.1
const crypto = require('node:crypto');
const algos = crypto.getHashes();
const plain = 'abcd';
const results = algos
.map(algo => ({
algo,
hash: crypto.createHash(algo).update(plain).digest('hex'),
}))
// multisort
.sort((a, b) => a.hash.length === b.hash.length
? a.hash.localeCompare(b.hash)
: (a.hash.length - b.hash.length)
)
console.table(results)
┌─────────┬──────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ (index) │ algo │ hash │
├─────────┼──────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ 0 │ 'RSA-MD4' │ '41decd8f579255c5200f86a4bb3ba740' │
│ 1 │ 'md4' │ '41decd8f579255c5200f86a4bb3ba740' │
│ 2 │ 'md4WithRSAEncryption' │ '41decd8f579255c5200f86a4bb3ba740' │
│ 3 │ 'shake128' │ '5360ce03ad4df5bb4337db4eccc0fb50' │
│ 4 │ 'RSA-MDC2' │ '55cb846052e0787713476acdc7ddc822' │
│ 5 │ 'mdc2' │ '55cb846052e0787713476acdc7ddc822' │
│ 6 │ 'mdc2WithRSA' │ '55cb846052e0787713476acdc7ddc822' │
│ 7 │ 'RSA-MD5' │ 'e2fc714c4727ee9395f324cd2e7f331f' │
│ 8 │ 'md5' │ 'e2fc714c4727ee9395f324cd2e7f331f' │
│ 9 │ 'md5WithRSAEncryption' │ 'e2fc714c4727ee9395f324cd2e7f331f' │
│ 10 │ 'ssl3-md5' │ 'e2fc714c4727ee9395f324cd2e7f331f' │
│ 11 │ 'RSA-RIPEMD160' │ '2e7e536fd487deaa943fda5522d917bdb9011b7a' │
│ 12 │ 'ripemd' │ '2e7e536fd487deaa943fda5522d917bdb9011b7a' │
│ 13 │ 'ripemd160' │ '2e7e536fd487deaa943fda5522d917bdb9011b7a' │
│ 14 │ 'ripemd160WithRSA' │ '2e7e536fd487deaa943fda5522d917bdb9011b7a' │
│ 15 │ 'rmd160' │ '2e7e536fd487deaa943fda5522d917bdb9011b7a' │
│ 16 │ 'RSA-SHA1' │ '81fe8bfe87576c3ecb22426f8e57847382917acf' │
│ 17 │ 'RSA-SHA1-2' │ '81fe8bfe87576c3ecb22426f8e57847382917acf' │
│ 18 │ 'sha1' │ '81fe8bfe87576c3ecb22426f8e57847382917acf' │
│ 19 │ 'sha1WithRSAEncryption' │ '81fe8bfe87576c3ecb22426f8e57847382917acf' │
│ 20 │ 'ssl3-sha1' │ '81fe8bfe87576c3ecb22426f8e57847382917acf' │
│ 21 │ 'RSA-SHA512/224' │ '0c9f157ab030fb06e957c14e3938dc5908962e5dd7b66f04a36fc534' │
│ 22 │ 'sha512-224' │ '0c9f157ab030fb06e957c14e3938dc5908962e5dd7b66f04a36fc534' │
│ 23 │ 'sha512-224WithRSAEncryption' │ '0c9f157ab030fb06e957c14e3938dc5908962e5dd7b66f04a36fc534' │
│ 24 │ 'RSA-SHA224' │ 'a76654d8e3550e9a2d67a0eeb6c67b220e5885eddd3fde135806e601' │
│ 25 │ 'sha224' │ 'a76654d8e3550e9a2d67a0eeb6c67b220e5885eddd3fde135806e601' │
│ 26 │ 'sha224WithRSAEncryption' │ 'a76654d8e3550e9a2d67a0eeb6c67b220e5885eddd3fde135806e601' │
│ 27 │ 'RSA-SHA3-224' │ 'dd886b5fd8421fb3871d24e39e53967ce4fc80dd348bedbea0109c0e' │
│ 28 │ 'id-rsassa-pkcs1-v1_5-with-sha3-224' │ 'dd886b5fd8421fb3871d24e39e53967ce4fc80dd348bedbea0109c0e' │
│ 29 │ 'sha3-224' │ 'dd886b5fd8421fb3871d24e39e53967ce4fc80dd348bedbea0109c0e' │
│ 30 │ 'shake256' │ '16c60651e6448eb9c177234fdd73ce60cbfe6d805c0e8f4c956986376be286d6' │
│ 31 │ 'RSA-SHA3-256' │ '6f6f129471590d2c91804c812b5750cd44cbdfb7238541c451e1ea2bc0193177' │
│ 32 │ 'id-rsassa-pkcs1-v1_5-with-sha3-256' │ '6f6f129471590d2c91804c812b5750cd44cbdfb7238541c451e1ea2bc0193177' │
│ 33 │ 'sha3-256' │ '6f6f129471590d2c91804c812b5750cd44cbdfb7238541c451e1ea2bc0193177' │
│ 34 │ 'blake2s256' │ '716748cce97a0abc942e1d491bc25102f5b6ff71ee62a86abd605a6c40120169' │
│ 35 │ 'RSA-SM3' │ '82ec580fe6d36ae4f81cae3c73f4a5b3b5a09c943172dc9053c69fd8e18dca1e' │
│ 36 │ 'sm3' │ '82ec580fe6d36ae4f81cae3c73f4a5b3b5a09c943172dc9053c69fd8e18dca1e' │
│ 37 │ 'sm3WithRSAEncryption' │ '82ec580fe6d36ae4f81cae3c73f4a5b3b5a09c943172dc9053c69fd8e18dca1e' │
│ 38 │ 'RSA-SHA256' │ '88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589' │
│ 39 │ 'sha256' │ '88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589' │
│ 40 │ 'sha256WithRSAEncryption' │ '88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589' │
│ 41 │ 'RSA-SHA512/256' │ 'd2891c7978be0e24948f37caa415b87cb5cbe2b26b7bad9dc6391b8a6f6ddcc9' │
│ 42 │ 'sha512-256' │ 'd2891c7978be0e24948f37caa415b87cb5cbe2b26b7bad9dc6391b8a6f6ddcc9' │
│ 43 │ 'sha512-256WithRSAEncryption' │ 'd2891c7978be0e24948f37caa415b87cb5cbe2b26b7bad9dc6391b8a6f6ddcc9' │
│ 44 │ 'md5-sha1' │ 'e2fc714c4727ee9395f324cd2e7f331f81fe8bfe87576c3ecb22426f8e57847382917acf' │
│ 45 │ 'RSA-SHA384' │ '1165b3406ff0b52a3d24721f785462ca2276c9f454a116c2b2ba20171a7905ea5a026682eb659c4d5f115c363aa3c79b' │
│ 46 │ 'sha384' │ '1165b3406ff0b52a3d24721f785462ca2276c9f454a116c2b2ba20171a7905ea5a026682eb659c4d5f115c363aa3c79b' │
│ 47 │ 'sha384WithRSAEncryption' │ '1165b3406ff0b52a3d24721f785462ca2276c9f454a116c2b2ba20171a7905ea5a026682eb659c4d5f115c363aa3c79b' │
│ 48 │ 'RSA-SHA3-384' │ '5af1d89732d4d10cc6e92a36756f68ecfbf7ae4d14ed4523f68fc304cccfa5b0bba01c80d0d9b67f9163a5c211cfd65b' │
│ 49 │ 'id-rsassa-pkcs1-v1_5-with-sha3-384' │ '5af1d89732d4d10cc6e92a36756f68ecfbf7ae4d14ed4523f68fc304cccfa5b0bba01c80d0d9b67f9163a5c211cfd65b' │
│ 50 │ 'sha3-384' │ '5af1d89732d4d10cc6e92a36756f68ecfbf7ae4d14ed4523f68fc304cccfa5b0bba01c80d0d9b67f9163a5c211cfd65b' │
│ 51 │ 'blake2b512' │ '26bc14024d5d6818ad7c4dee519353c290e38b6535f16f62b6ce5c6ff346c354542496f89b84eacffa1da51f0ac5e643f965637cc24e0b3f819bdae05f3932b0' │
│ 52 │ 'RSA-SHA3-512' │ '6eb7b86765bf96a8467b72401231539cbb830f6c64120954c4567272f613f1364d6a80084234fa3400d306b9f5e10c341bbdc5894d9b484a8c7deea9cbe4e265' │
│ 53 │ 'id-rsassa-pkcs1-v1_5-with-sha3-512' │ '6eb7b86765bf96a8467b72401231539cbb830f6c64120954c4567272f613f1364d6a80084234fa3400d306b9f5e10c341bbdc5894d9b484a8c7deea9cbe4e265' │
│ 54 │ 'sha3-512' │ '6eb7b86765bf96a8467b72401231539cbb830f6c64120954c4567272f613f1364d6a80084234fa3400d306b9f5e10c341bbdc5894d9b484a8c7deea9cbe4e265' │
│ 55 │ 'whirlpool' │ 'bda164f0b930c43a1bacb5df880b205d15ac847add35145bf25d991ae74f0b72b1ac794f8aacda5fcb3c47038c954742b1857b5856519de4d1e54bfa2fa4eac5' │
│ 56 │ 'RSA-SHA512' │ 'd8022f2060ad6efd297ab73dcc5355c9b214054b0d1776a136a669d26a7d3b14f73aa0d0ebff19ee333368f0164b6419a96da49e3e481753e7e96b716bdccb6f' │
│ 57 │ 'sha512' │ 'd8022f2060ad6efd297ab73dcc5355c9b214054b0d1776a136a669d26a7d3b14f73aa0d0ebff19ee333368f0164b6419a96da49e3e481753e7e96b716bdccb6f' │
│ 58 │ 'sha512WithRSAEncryption' │ 'd8022f2060ad6efd297ab73dcc5355c9b214054b0d1776a136a669d26a7d3b14f73aa0d0ebff19ee333368f0164b6419a96da49e3e481753e7e96b716bdccb6f' │
└─────────┴──────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment