0
$\begingroup$

I am looking for a very simple example of cryptography hash chain source code. Could you forward me some examples or link, guys? For example, https://en.wikipedia.org/wiki/Hash_chain [1]. h(h(h(h(x)))) gives a hash chain of length 4. h=hash, x=password

$\endgroup$

closed as off-topic by otus, yyyyyyy, DrLecter, Maarten Bodewes, e-sushi Apr 26 '16 at 18:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Cannot understand hash-chain without source codes $\endgroup$ – Amon Olimov Apr 26 '16 at 5:17
  • 1
    $\begingroup$ I'm voting to close this question as off-topic because its a programming question and no crypto question. $\endgroup$ – DrLecter Apr 26 '16 at 8:24
  • $\begingroup$ You'd need a salt as well to be reasonably secure for passwords. Use a PBKDF such as PBKDF2. $\endgroup$ – Maarten Bodewes Apr 26 '16 at 10:24
2
$\begingroup$

I'm not a Java programmer, and I didn't compile this, but I modified answer to this question to achieve a hash chain of length equal to four.

byte[] bytesOfMessage = yourString.getBytes("UTF-8");

MessageDigest md = MessageDigest.getInstance("MD5");

byte[] thedigest = md.digest(md.digest(md.digest(md.digest(bytesOfMessage))));

PS. Don't use MD5 for crypto. It's not secure.

$\endgroup$
  • $\begingroup$ So why do you use MD5 in your example? $\endgroup$ – Maarten Bodewes Apr 26 '16 at 10:23
  • $\begingroup$ I didn't want to change the sources in any other way then adding the chain to allow everyone easy way of spotting the differences between my answer and the linked one. $\endgroup$ – Filip Franik Apr 26 '16 at 12:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.