我有一个包含哈希的文件,我需要做的是将所有特定哈希与正则表达式匹配,如果有更简单的方法请详细说明,但是这个文件包含多种不同类型的哈希:
请注意,散列类型仅在此文件中用于测试目的,散列类型不在文件中
SHA1 => a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
SHA1 => c8cc3f3b4b33523b8c180da8562a5dc42a00677c
SHA1 => abf6021ef8e11106b894bea04c03e9d8a8de17a6
SHA224 => 90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809
SHA224 => 40e223e699912131a99ee76c5e065827373c67bdfaf99d944fe8dfc8
SHA224 => 2acb3a17dd92e2bf54b345b3711e8ead183e01794aafced5ed4ad23e
SHA => f8d3b312442a67706057aeb45b983221afb4f035
SHA => 0c37a678e8eef041b82b3025e64fc01a670bb0f0
SHA => 1f77da8f9d10720e6bbd35b0b998bd7f0bb79381
SHA384 => 768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9
SHA384 => 67d36f4834cb7e79788381f849c21a63b968732bf0f3fac24bf4b24423b797fd12269e2cd7fa428bdc86a48ada5e3577
SHA384 => b66651b7190abc1abdb8c7829207a06335045c353b748462a193042be584603a85587b95806f3fef1da8b1da983d5fb1
ecdsa-with-SHA1 => a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
ecdsa-with-SHA1 => c8cc3f3b4b33523b8c180da8562a5dc42a00677c
ecdsa-with-SHA1 => abf6021ef8e11106b894bea04c03e9d8a8de17a6
SHA256 => 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
SHA256 => 34ad260fd7ffae7f4b5c716da1d9d422f95775a5f6f5b910201adfa303ef26a8
SHA256 => 8f2cfb70a71a9f40f95322d176998edce14122a16fa208a8b1cc993d36df3f1d
SHA512 => ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc
5fa9ad8e6f57f50028a8ff
SHA512 => d0351496ef238247ccba08518f10678a6211080a98a6128fa49bd225a2bbec360e3e1b93759f68c14ae3b95096fd81682c1f4a1453
e0057af4a55a910d3066b2
SHA512 => b4cc5ce80cc15910c6e87b15adf1df5485f3165bb02cd5e2d95d3174e137de1d1b6eb0f67ace107f16a234682edd72a6896645969b
19691f38a12199dfc5007e
md4 => db346d691d7acc4dc2625db19f9e3f52
md4 => 4506d07a12e2d2b8f26485a455d6c69f
md4 => 369ee30df7b4b261d5dcd5b607ffca17
md5 => 098f6bcd4621d373cade4e832627b4f6
md5 => cb466b639885e93973c0a272c339ff9a
md5 => ae696df69ec720fbb46d52ebbc262fc8
sha1 => a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
sha1 => c8cc3f3b4b33523b8c180da8562a5dc42a00677c
sha1 => abf6021ef8e11106b894bea04c03e9d8a8de17a6
dsaWithSHA => a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
dsaWithSHA => c8cc3f3b4b33523b8c180da8562a5dc42a00677c
dsaWithSHA => abf6021ef8e11106b894bea04c03e9d8a8de17a6
DSA-SHA => a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
DSA-SHA => c8cc3f3b4b33523b8c180da8562a5dc42a00677c
DSA-SHA => abf6021ef8e11106b894bea04c03e9d8a8de17a6
sha224 => 90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809
sha224 => 40e223e699912131a99ee76c5e065827373c67bdfaf99d944fe8dfc8
sha224 => 2acb3a17dd92e2bf54b345b3711e8ead183e01794aafced5ed4ad23e
dsaEncryption => a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
dsaEncryption => c8cc3f3b4b33523b8c180da8562a5dc42a00677c
dsaEncryption => abf6021ef8e11106b894bea04c03e9d8a8de17a6
DSA => a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
DSA => c8cc3f3b4b33523b8c180da8562a5dc42a00677c
DSA => abf6021ef8e11106b894bea04c03e9d8a8de17a6
ripemd160 => 5e52fee47e6b070565f74372468cdc699de89107
ripemd160 => b36b88d174a4d7cd16150f0071f150e74939bdcb
ripemd160 => 3d8e0e6cdf562d919887da3af417aa2ecdfa3031
sha => f8d3b312442a67706057aeb45b983221afb4f035
sha => 0c37a678e8eef041b82b3025e64fc01a670bb0f0
sha => 1f77da8f9d10720e6bbd35b0b998bd7f0bb79381
MD5 => 098f6bcd4621d373cade4e832627b4f6
MD5 => cb466b639885e93973c0a272c339ff9a
MD5 => ae696df69ec720fbb46d52ebbc262fc8
MD4 => db346d691d7acc4dc2625db19f9e3f52
MD4 => 4506d07a12e2d2b8f26485a455d6c69f
MD4 => 369ee30df7b4b261d5dcd5b607ffca17
sha384 => 768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9
sha384 => 67d36f4834cb7e79788381f849c21a63b968732bf0f3fac24bf4b24423b797fd12269e2cd7fa428bdc86a48ada5e3577
sha384 => b66651b7190abc1abdb8c7829207a06335045c353b748462a193042be584603a85587b95806f3fef1da8b1da983d5fb1
sha256 => 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
sha256 => 34ad260fd7ffae7f4b5c716da1d9d422f95775a5f6f5b910201adfa303ef26a8
sha256 => 8f2cfb70a71a9f40f95322d176998edce14122a16fa208a8b1cc993d36df3f1d
sha512 => ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc
5fa9ad8e6f57f50028a8ff
sha512 => d0351496ef238247ccba08518f10678a6211080a98a6128fa49bd225a2bbec360e3e1b93759f68c14ae3b95096fd81682c1f4a1453
e0057af4a55a910d3066b2
sha512 => b4cc5ce80cc15910c6e87b15adf1df5485f3165bb02cd5e2d95d3174e137de1d1b6eb0f67ace107f16a234682edd72a6896645969b
19691f38a12199dfc5007e
RIPEMD160 => 5e52fee47e6b070565f74372468cdc699de89107
RIPEMD160 => b36b88d174a4d7cd16150f0071f150e74939bdcb
RIPEMD160 => 3d8e0e6cdf562d919887da3af417aa2ecdfa3031
whirlpool => b913d5bbb8e461c2c5961cbe0edcdadfd29f068225ceb37da6defcf89849368f8c6c2eb6a4c4ac75775d032a0ecfdfe85505730
62b653fe92fc7b8fb3b7be8d6
whirlpool => 838b401be3e04657e0559bc338ec1ac71cd810f35dadd9183152f9ceec089458a487ba11d871c1f1bc313a15b2e1f5cefd59a75
1724b0e0562c8bb616bfb6ee8
whirlpool => 6755e2341ff4cf4b50c6287f1809e217bb9b37d2eeeecd01cb720644c072cb51528377c1ab0de5462496efac14221b6c236bb30
96d386e186c59ab102c826ec3
我已经为MD5提出了这个正则表达式:([a-fA-F\d]{32,40})
这是有效的,但它也匹配几乎一半的SHA哈希值,例如:
ae696df69ec720fbb46d52ebbc262fc8 #<= match
369ee30df7b4b261d5dcd5b607ffca17 #<= match
d0351496ef238247ccba08518f10678a <= match continue hash => 6211080a98a6128fa49bd225a2bbec360e3e1b93759f68c14ae3b95096fd81682c1f4a1453
e0057af4a55a910d3066b2
有没有办法可以匹配仅 MD哈希值(md4
,md5
),以及仅 SHA哈希值{{1 },sha512
,sha384
等等。)?
答案 0 :(得分:2)
你可以依靠正则表达式中的OR
符号|
来捕捉你需要的东西。这仅在哈希值具有特定长度时才有效。根据@ chris85评论,我们可以使用sha512
进一步添加sha384
和|
,方法是指定例如sha512只有{52,60}
个字符,而sha384只有{92,100}
个字符, 等等。它将是这样的:
^(?:[a-fA-F\d]{32,40})$|^(?:[a-fA-F\d]{52,60})$|^(?:[a-fA-F\d]{92,100})$
演示:https://regex101.com/r/z5SoCS/1
您可以使用组进一步增强正则表达式,并为每个哈希指定名称。例如,您可以执行以下操作:
^(?<sha384>[a-fA-F\d]{92,100})$
答案 1 :(得分:1)
您无法通过检查输出来告诉创建哈希的哈希算法。
问题中的所有哈希值都以十六进制表示,因此无法通过其内容告知创建的哈希值。
可以做的最好的事情是查看长度,但会有几个哈希可以创建一个特定的长度。
如果您需要知道哈希,则需要以某种方式对哈希进行编码,例如前缀。