How to set MessageDigest seed?

你说的曾经没有我的故事 提交于 2019-12-06 12:01:51

Where do you see the need for a seed in a SHA-1 digest? Normally in encryption algorithm with a need of source of random numbers, a seed is "needed". But in SHA-1 you don't even use random numbers at all, so there is no seed or initial vector to set. The variables you mentioned are 'hard' (constants), they are part of the algorithm, no need or use to change the values of h0-4.

I recommend using a salt instead of a seed for MessageDigest family hash functions. A salt is applied by, for example, prepending the salt bytes to the input.

Prepending a salt is also more powerful than directly setting the seed values, because in addition to changing the internal state of the hash, if the salt is not a multiple of the digest block size then it can also perturb the alignment with which the input is fed into the hash function.

The Java function cannot be supplied with an initial seed.

I copied a C implementation of SHA-1 algorithm and modified it to allow changing of the initial seed values.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!