加密算法列表

44

我正在尝试查找一组可以用作加密算法的字符串列表,以替换此函数中的SHA256

crypto.createHmac("SHA256", secret).update(string).digest('base64'),

我明白加密货币使用openssl,而且算法是特定于运行node.js的每个系统的。

使用以下命令可以查看您的系统中所有可用算法的列表。

openssl list-cipher-algorithms 
openssl list-cipher-commands 

我已经将这两个命令的内容输出到此Gist

令我困扰的是,SHA256 在这些列表中都没有出现。

我真的很想得到明确的算法列表。

5个回答

84

这里的教训是,ciphershashes是不同的并且使用不同的算法。在node中使用crypto对象的.getCiphers().getHashes()方法来分别返回支持的ciphershashes的名称数组。

var crypto = require('crypto')
console.log(crypto.getCiphers())
console.log(crypto.getHashes())

以下记录了哪些加密算法:

[ 'CAST-cbc',
  'aes-128-cbc',
  'aes-128-cbc-hmac-sha1',
  'aes-128-cfb',
  'aes-128-cfb1',
  'aes-128-cfb8',
  'aes-128-ctr',
  'aes-128-ecb',
  'aes-128-gcm',
  'aes-128-ofb',
  'aes-128-xts',
  'aes-192-cbc',
  'aes-192-cfb',
  'aes-192-cfb1',
  'aes-192-cfb8',
  'aes-192-ctr',
  'aes-192-ecb',
  'aes-192-gcm',
  'aes-192-ofb',
  'aes-256-cbc',
  'aes-256-cbc-hmac-sha1',
  'aes-256-cfb',
  'aes-256-cfb1',
  'aes-256-cfb8',
  'aes-256-ctr',
  'aes-256-ecb',
  'aes-256-gcm',
  'aes-256-ofb',
  'aes-256-xts',
  'aes128',
  'aes192',
  'aes256',
  'bf',
  'bf-cbc',
  'bf-cfb',
  'bf-ecb',
  'bf-ofb',
  'blowfish',
  'camellia-128-cbc',
  'camellia-128-cfb',
  'camellia-128-cfb1',
  'camellia-128-cfb8',
  'camellia-128-ecb',
  'camellia-128-ofb',
  'camellia-192-cbc',
  'camellia-192-cfb',
  'camellia-192-cfb1',
  'camellia-192-cfb8',
  'camellia-192-ecb',
  'camellia-192-ofb',
  'camellia-256-cbc',
  'camellia-256-cfb',
  'camellia-256-cfb1',
  'camellia-256-cfb8',
  'camellia-256-ecb',
  'camellia-256-ofb',
  'camellia128',
  'camellia192',
  'camellia256',
  'cast',
  'cast-cbc',
  'cast5-cbc',
  'cast5-cfb',
  'cast5-ecb',
  'cast5-ofb',
  'des',
  'des-cbc',
  'des-cfb',
  'des-cfb1',
  'des-cfb8',
  'des-ecb',
  'des-ede',
  'des-ede-cbc',
  'des-ede-cfb',
  'des-ede-ofb',
  'des-ede3',
  'des-ede3-cbc',
  'des-ede3-cfb',
  'des-ede3-cfb1',
  'des-ede3-cfb8',
  'des-ede3-ofb',
  'des-ofb',
  'des3',
  'desx',
  'desx-cbc',
  'id-aes128-GCM',
  'id-aes192-GCM',
  'id-aes256-GCM',
  'idea',
  'idea-cbc',
  'idea-cfb',
  'idea-ecb',
  'idea-ofb',
  'rc2',
  'rc2-40-cbc',
  'rc2-64-cbc',
  'rc2-cbc',
  'rc2-cfb',
  'rc2-ecb',
  'rc2-ofb',
  'rc4',
  'rc4-40',
  'rc4-hmac-md5',
  'seed',
  'seed-cbc',
  'seed-cfb',
  'seed-ecb',
  'seed-ofb' ]

还有以下哈希值:

[ 'DSA',
  'DSA-SHA',
  'DSA-SHA1',
  'DSA-SHA1-old',
  'RSA-MD4',
  'RSA-MD5',
  'RSA-MDC2',
  'RSA-RIPEMD160',
  'RSA-SHA',
  'RSA-SHA1',
  'RSA-SHA1-2',
  'RSA-SHA224',
  'RSA-SHA256',
  'RSA-SHA384',
  'RSA-SHA512',
  'dsaEncryption',
  'dsaWithSHA',
  'dsaWithSHA1',
  'dss1',
  'ecdsa-with-SHA1',
  'md4',
  'md4WithRSAEncryption',
  'md5',
  'md5WithRSAEncryption',
  'mdc2',
  'mdc2WithRSA',
  'ripemd',
  'ripemd160',
  'ripemd160WithRSA',
  'rmd160',
  'sha',
  'sha1',
  'sha1WithRSAEncryption',
  'sha224',
  'sha224WithRSAEncryption',
  'sha256',
  'sha256WithRSAEncryption',
  'sha384',
  'sha384WithRSAEncryption',
  'sha512',
  'sha512WithRSAEncryption',
  'shaWithRSAEncryption',
  'ssl2-md5',
  'ssl3-md5',
  'ssl3-sha1',
  'whirlpool' ]

这是我的设置:

  • openssl versionOpenSSL 0.9.8zg 14 July 2015
  • node --versionv0.12.4

1
@ThomasRegii,谢谢,这是更加针对Node.js的回答。 - Jevgeni Smirnov
您可能想在这里阅读有关加密算法的内容:https://dev59.com/3G035IYBdhLWcg3wNtNw - Fandi Susanto
1
@ThomasRegii,我知道这是一篇旧帖子。你知道是什么决定了密码列表吗?它是由Nodejs版本还是运行计算机确定的? - Nathan H

4

4
CAST-cbc
aes-128-cbc

aes-128-cbc-hmac-sha1

aes-128-cfb

aes-128-cfb1

aes-128-cfb8

aes-128-ctr

aes-128-ecb

aes-128-gcm

aes-128-ofb

aes-128-xts

aes-192-cbc

aes-192-cfb

aes-192-cfb1

aes-192-cfb8

aes-192-ctr

aes-192-ecb

aes-192-gcm

aes-192-ofb

aes-256-cbc

aes-256-cbc-hmac-sha1

aes-256-cfb

aes-256-cfb1

aes-256-cfb8

aes-256-ctr

aes-256-ecb

aes-256-gcm

aes-256-ofb

aes-256-xts

aes128

aes192

aes256

bf

bf-cbc

bf-cfb

bf-ecb

bf-ofb

blowfish

camellia-128-cbc

camellia-128-cfb

camellia-128-cfb1

camellia-128-cfb8

camellia-128-ecb

camellia-128-ofb

camellia-192-cbc

camellia-192-cfb

camellia-192-cfb1

camellia-192-cfb8

camellia-192-ecb

camellia-192-ofb

camellia-256-cbc

camellia-256-cfb

camellia-256-cfb1

camellia-256-cfb8

camellia-256-ecb

camellia-256-ofb

camellia128

camellia192

camellia256

cast

cast-cbc

cast5-cbc

cast5-cfb

cast5-ecb

cast5-ofb

des

des-cbc

des-cfb

des-cfb1

des-cfb8

des-ecb

des-ede

des-ede-cbc

des-ede-cfb

des-ede-ofb

des-ede3

des-ede3-cbc

des-ede3-cfb

des-ede3-cfb1

des-ede3-cfb8

des-ede3-ofb

des-ofb

des3

desx

desx-cbc

id-aes128-GCM

id-aes192-GCM

id-aes256-GCM

idea

idea-cbc

idea-cfb

idea-ecb

idea-ofb

rc2

rc2-40-cbc

rc2-64-cbc

rc2-cbc

rc2-cfb

rc2-ecb

rc2-ofb

rc4

rc4-40

rc4-hmac-md5

seed

seed-cbc

seed-cfb

seed-ecb

seed-ofb

3

SHA-256 不是密码,而是一个哈希算法。这可能就是为什么您在密码列表中没有找到它的原因。

同样,MD5和所有不同的SHA算法也属于哈希算法。

事实上,哈希算法正是你需要用于HMAC的算法类型。如果你希望基于块密码构建MAC,你就需要使用其他构造方式,例如OMAC/CMACPMAC或者CBC-MAC


1
谢谢您,我完全不知道。 - ThomasReggi

1

我检查了所有的密码字符串和我的gist,这些是唯一能与密码一起创建HMAC的算法。

MD5
SHA
SHA1
SHA256
SHA384

大多数情况下最好等待一段时间(一两天)让其他人发布答案,特别是因为你的答案是完全错误的 :) 最好在它被彻底删除之前将其删除。 - Maarten Bodewes
@owlstead 请提供另一种可用于创建HMAC的方法。如果你不能,那么我是正确的。我已经循环遍历了此页面上提供的所有字符串,除了上述字符串外,其他都会产生错误。 - ThomasReggi
问题更多地在于“cipher”这个名称(请注意拼写),因为创建HMAC需要哈希函数,只要此列表反映了openssl中的哈希函数,它就是正确的(很可能在以后的版本中会添加对SHA-224、SHA-512/256和/或SHA-3的支持)。 - Maarten Bodewes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接