以前java项目最近打算用node.js重写,但是加密这里实在没搞定。java中加密是:1024次加盐sha-1加密, 一个例子:salt:47998d63768aa877,密文:bef36ba826b045a7c5e536a2f7131a6c232eee36,明文:yunstudio2013 下面是java代码: private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) { try { MessageDigest digest = MessageDigest.getInstance(algorithm); if (salt != null) { digest.update(salt); } byte[] result = digest.digest(input); for (int i = 1; i < iterations; i++) { digest.reset(); result = digest.digest(result); } return result; } catch (GeneralSecurityException e) { throw Exceptions.unchecked(e); } } 我在js里面是这么干的,但是结果一直不对,代码如下: //bef36ba826b045a7c5e536a2f7131a6c232eee36 var hash = crypto.createHmac(“sha1”, “47998d63768aa877”).update(“yunstudio2013”).digest(“hex”); for (var i = 1; i < 1024; i++) { hash = crypto.createHmac(“sha1”, “47998d63768aa877”).update(hash).digest(“hex”); console.log(hash); } 求给个js代码~~~
看是不是你需要的 https://github.com/fundon/pbkdf2
给你看两个方法,你参考一下: https://gist.github.com/huaoguo/348cce6ba08c6dc91c29
thanks