【问题标题】:What is the best approach for password encryption [closed]密码加密的最佳方法是什么[关闭]
【发布时间】:2022-01-25 09:57:41
【问题描述】:

从前端到后端的最佳做法是加密在前端注册过程中收到的密码。例如,我应该在前端加密并发送,然后在后端重新加密吗?如果您能具体回答 node.js,我将不胜感激

【问题讨论】:

  • 您不应该加密密码。你应该用一些盐把它们哈希一下。您还应该使用库而不是自己编写这些东西。你最终会弄错的。
  • 您应该通过https将密码从前端传输到后端。这将在传输中提供加密保护。然后,在后端,您需要使用盐实现适当的散列并仅存储散列/盐。要测试未来的密码,您需要对未来的密码进行哈希处理,并与之前存储的哈希值进行比较。
  • 非常感谢您的回答,不知道有没有关于这个主题的教程或文章您可以推荐?
  • 关于存储散列密码crackstation.net/hashing-security.htm精心设计的密钥拉伸算法,如PBKDF2、bcrypt和scrypt。
  • 这是一个Information Security 的问题。见How to securely hash passwords?。但是,在搜索可能的重复项之前,您应该在那里询问...

标签: node.js encryption bcrypt password-protection sha


【解决方案1】:
    const bcrypt = require('bcrypt');
    const SimpleCrypto = require('simple-crypto-js').default;
    const _secretKey = "YOURKEYHERE"; //key for create hash key 
    const simpleCrypto = new SimpleCrypto(_secretKey);
    const saltRounds = 12;
    
    exports.createHashPwd = function (password) {
      return bcrypt.hashSync(password, saltRounds);
    };
    
    //create hashpassword string
    const hashPassword = await passwordService.createHashPwd(plainTextPd);

您可以在这里https://www.npmjs.com/package/simple-crypto-js了解更多信息

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2012-12-29
  • 1970-01-01
  • 2011-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-10
  • 2020-09-09
  • 2011-07-16
相关资源
最近更新 更多