zoukankan      html  css  js  c++  java
  • Salted hash password

    参考文档

    http://www.cnblogs.com/richardlee/articles/2511321.html

    https://en.wikipedia.org/wiki/Salt_%28cryptography%29

    https://www.91ri.org/7593.html

    密码存储为什么不能是明文?

    当账户密码是明文存储的话, 万一本网站给黑客攻破获取了数据, 则用户的账户被泄露。(术语叫 拖库)

    当黑客知道了你的账户后, 其可以使用此账户,到其他网站尝试访问, 例如有厉害关系的网站, 银行等。 (术语叫 撞库)

    一般来说, 普通用户为了减少密码记忆负担, 则容易在所有网站, 设置相同密码。

    为了减少用户注册登陆流程,新的网站一般使用公共账户认证服务, 例如(qq 微信 等), 这样也可以减少拖库撞库危险。

    密码应该以hash形式存储?

    不能以明文形式存储, 自然以密文方式存储。

    如果使用 对称加密方式, 则加密和解密的秘钥, 必须存储在网站上, 一旦密钥和算法泄露 并且 库被拖走, 密码就可以被直接计算出来,则密码的安全性仍然不能保证。

     密码以hash方式存储, 则保证密码不能被反向计算出来, 就算网站的维护人员, 也不能查看到原始密码是多少。 最多其能看到一串 hash值。

    黑客就算拿到hash值, 由于hash值不能被反向还原, 例如 MD5 SHA, 也只能悻悻然。

    这样保证用户密码的安全性。

    密码计算hash为什么要添加salt?

    试想,如果对于每个密码, 都直接采用某种hash算法, 计算得到hash值。

    对于一些简单密码, 其hash值是固定的, 则可以构造所有 最易使用的简单密码 的 hash值 成为一个表,

    当黑客拖库拿到 密码的 hash值后,  其使用构造表中的 hash值比较, 如果你相等, 则得到 密码的原始值。

    所以每年都有最弱密码排名, 提醒广大互联网用户, 不要使用简单密码。

    http://tech.163.com/12/1029/04/8EV6LS9U000915BF.html

    对于每一个密码都生成一个随机数(salt), 计算hash值的时候,将 salt 和 密码拼接后作为入参, 得到的hash值, 可以解决一张hash表, 尝试破解所有密码的问题。

    但是对于单个密码, 其salt也被泄露, 如果即时构造一个 带salt的 hash表, 同样也可以破解密码。

    如何加salt?

    http://www.cnblogs.com/richardlee/articles/2511321.html

    How long should the salt be?

    The salt should be at least as long as the hash function. For example, if your hash function is 256 bits, then you should have a salt of at least 256 bits. I find that the easiest way to generate enough salt is to generate a random string of hex characters that is the same length as the hash function output (64 hex characters for 256 bits). First and foremost, your salt should be long enough so that no two users' passwords will ever be hashed using the same salt.

    How do I generate the salt?

    Use a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG). Do NOT use your language's math library's rand() function. There will be a proper CSPRNG for you to use. In PHP, it's mcrypt_create_iv() and in .NET it's System.Security.Cryptography.RNGCryptoServiceProvider. The imporant thing is that the salt is uniquefor each user. Using a high quality CSPRNG to generate a long salt will practically guarantee uniqueness without needing to manually check if the salt has been used before.

    如何选择hash算法?

    What hash algorithm should I use?

    DO use:

    DO NOT use:

      • MD5
      • SHA0 or SHA1
      • crypt unless it uses SHA256 or SHA512
      • Any algorithm that you made yourself or hasn't gone through an intensive peer review process like the SHA3 competition

    是否加了盐, 密码就安全了?

    不是的, 添加了salt,是提高了破解的难度。  但是如果密码本身是不安全的, 例如非常简单的规则 纯数字 , 则很容易被破解。 不管是否添加salt。

    所以一些网站要求, 密码 必须包含 字母 数字, 外还必须添加一种特殊符号。

  • 相关阅读:
    docker
    C语言课程设计:校车管理系统(附源码)
    【DW打卡-计算机视觉基础】06 边缘检测
    【DW打卡-计算机视觉基础】05 图像分割/二值化
    【DW打卡-计算机视觉基础】04_图像滤波
    【DW打卡-计算机视觉基础】03_彩色空间互转
    【DW打卡-计算机视觉基础】02_OpenCV的几何变换--旋转和平移
    【DW打卡-计算机视觉基础】01_OpenCV框架与图像插值算法
    机器学习01-入门
    [js]网页中添加水印
  • 原文地址:https://www.cnblogs.com/lightsong/p/5186189.html
Copyright © 2011-2022 走看看