我想翻譯 Blynk IoT 軟件中使用的 Java 代碼密碼哈希,我可以在 Express.js 應(yīng)用程序中使用它。謝謝你的幫助!Java代碼: https: //www.onlinegdb.com/HJe19lyFBimport java.nio.charset.StandardCharsets;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import java.util.Base64;public class Main { public static void main(String[] args){ System.out.println(makeHash("password","mail@gmail.com")); } private static final String SHA_256 = "SHA-256"; private Main() { try { MessageDigest.getInstance(SHA_256); } catch (NoSuchAlgorithmException e) { } } public static String makeHash(String password, String salt) { try { MessageDigest md = MessageDigest.getInstance(SHA_256); md.update(password.getBytes(StandardCharsets.UTF_8)); byte[] byteData = md.digest(makeHash(salt.toLowerCase())); return Base64.getEncoder().encodeToString(byteData); } catch (Exception e) { //ignore, will never happen. } return password; } private static byte[] makeHash(String val) throws NoSuchAlgorithmException { return MessageDigest.getInstance(SHA_256).digest(val.getBytes(StandardCharsets.UTF_8)); }}目前不起作用的解決方案: https ://repl.it/@patryk0493/blynk-password-hashing
1 回答

紅糖糍粑
TA貢獻(xiàn)1815條經(jīng)驗 獲得超6個贊
您可以使用標(biāo)準(zhǔn) Node.js加密模塊重新實現(xiàn) Java 密碼哈希:
const crypto = require('crypto');
const makeHash = (data) => {
? const hash = crypto.createHash('sha256');
? return hash.update(data, 'utf8');
}
const password = "password";
const salt = "mail@gmail.com";
const result = makeHash(password)
? .update(makeHash(salt).digest())
? .digest('base64')
console.log(result);
添加回答
舉報
0/150
提交
取消