我如何用sha256散列x次并将它们输出到文件或在屏幕上显示它们


How do I hash something x times with sha256 and output them into a file or show them on screen?

例如,我想对密码散列10次,它看起来像这样
1. 6 b3a55e0261b0304143f805a24924d0c1c44524821305f31d9277843b8a10f4e
2. 3 e49d361ee0f48388c7383d80703c80a773555f9e0bd563f559310abb14680a0
3.c3e1ff07b9a1b4bcf26860c2e99cb5566720052e71ac6fb531e3de36e412e36a
4. 730年f32f9074394d5afd5f401d0eaa67a7566897bdb450ab4d5d4fa3c3a24b948

function hash_pass($pass, $times = 10){
    for($i = 0; $i < $times; $i++){
         $pass = hash('sha256', $pass);
         echo $pass;
    }
}

但是你为什么要对密码进行这么多次哈希呢?如果你担心安全问题,我建议你读一些关于安全的东西。这篇文章可能对你有帮助。

1:写一个哈希函数

function hashCode(s){
  return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);              
}

2:多次运行:

var times = 10, i = 0, password = "xxxxxxxxxxxxxxx", outputStr = "";
while(i<=times){
  outputStr +=hashCode(password) + "'n";
  i++;
}
//out put the string
console.log(outputStr);