开发者

Check if a string is xxx-bits hashed

How do I check if a string was hashed up to a certain bits? I want to unit test my method (which uses SHA512), I want to write a test to check if that 开发者_如何学Cstring returned was 512-bit hashed.


You can't determine if the string is encrypted only with the string itself. One could enter data that is similar to the result of your SHA512 hash function, but without being actually hashed.

If you know that it is hashed and you want to know if SHA512 was used, the only thing you can verify is if the string is 512 bit long, but that wont tell you for sure if it's SHA512.


If it's a one-way hash (you don't state that it is, but your use of SHA512 implies it), then it can't be decrypted. Really, the only way to test it is to:

  • Take known input (i.e., a known plaintext string).
  • Calculate, by other means that you trust, what the expected encryption output should be.
  • Ensure that your program or routine produces that output for that string.

Repeat with various inputs, until you're satisfied.


Please repeat after me: Hashing is not Encryption. The input data for your hash algorithm is lost, and cannot be recovered.

SHA-512 has an output 512 bits long, so someone presenting you with 512 bits and saying it's the output of a SHA-512 algorithm could be correct. As far as I know there's no readily identifable pattern to the output of SHA algorithm though, so they could be just presenting you with 512 bits of pure random noise.

Can you explain why you would want to identify the algorithm used to generate a particular hash?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜