• <small id='t4RZH'></small><noframes id='t4RZH'>

    <i id='t4RZH'><tr id='t4RZH'><dt id='t4RZH'><q id='t4RZH'><span id='t4RZH'><b id='t4RZH'><form id='t4RZH'><ins id='t4RZH'></ins><ul id='t4RZH'></ul><sub id='t4RZH'></sub></form><legend id='t4RZH'></legend><bdo id='t4RZH'><pre id='t4RZH'><center id='t4RZH'></center></pre></bdo></b><th id='t4RZH'></th></span></q></dt></tr></i><div id='t4RZH'><tfoot id='t4RZH'></tfoot><dl id='t4RZH'><fieldset id='t4RZH'></fieldset></dl></div>
    <legend id='t4RZH'><style id='t4RZH'><dir id='t4RZH'><q id='t4RZH'></q></dir></style></legend>

      1. <tfoot id='t4RZH'></tfoot>

          <bdo id='t4RZH'></bdo><ul id='t4RZH'></ul>
      2. 高质量、简单的随机密码生成器

        时间:2023-09-28
        <legend id='MyEDa'><style id='MyEDa'><dir id='MyEDa'><q id='MyEDa'></q></dir></style></legend>

        1. <small id='MyEDa'></small><noframes id='MyEDa'>

            <tfoot id='MyEDa'></tfoot>
              <i id='MyEDa'><tr id='MyEDa'><dt id='MyEDa'><q id='MyEDa'><span id='MyEDa'><b id='MyEDa'><form id='MyEDa'><ins id='MyEDa'></ins><ul id='MyEDa'></ul><sub id='MyEDa'></sub></form><legend id='MyEDa'></legend><bdo id='MyEDa'><pre id='MyEDa'><center id='MyEDa'></center></pre></bdo></b><th id='MyEDa'></th></span></q></dt></tr></i><div id='MyEDa'><tfoot id='MyEDa'></tfoot><dl id='MyEDa'><fieldset id='MyEDa'></fieldset></dl></div>

                  <bdo id='MyEDa'></bdo><ul id='MyEDa'></ul>

                    <tbody id='MyEDa'></tbody>
                  本文介绍了高质量、简单的随机密码生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有兴趣创建一个非常简单、高质量(加密)的随机密码生成器.有没有更好的方法来做到这一点?

                  I'm interested in creating a very simple, high (cryptographic) quality random password generator. Is there a better way to do this?

                  import os, random, string
                  
                  length = 13
                  chars = string.ascii_letters + string.digits + '!@#$%^&*()'
                  random.seed = (os.urandom(1024))
                  
                  print ''.join(random.choice(chars) for i in range(length))
                  

                  推荐答案

                  密码的难点在于让它们足够强大并且仍然能够记住它们.如果密码不应该被人类记住,那么它就不是真正的密码.

                  The difficult thing with passwords is to make them strong enough and still be able to remember them. If the password is not meant to be remembered by a human being, then it is not really a password.

                  您使用 Python 的 os.urandom():这很好.对于任何实际目的(甚至密码学),os.urandom() 的输出与真正的 alea 没有区别.然后你将它用作 random 中的种子,这不太好:它是一个非加密 PRNG,它的输出可能会表现出一些不会在统计测量工具中注册的结构,但可能是被聪明的攻击者利用.您应该一直使用 os.urandom().为简单起见:选择长度为 64 的字母表,例如字母(大写和小写)、数字和两个额外的标点符号(例如+"和/").然后,对于每个密码字符,从 os.urandom() 中获取一个字节,以 64 为模减少值(这是无偏的,因为 64 除以 256)并将结果用作 chars 中的索引 数组.

                  You use Python's os.urandom(): that's good. For any practical purpose (even cryptography), the output of os.urandom() is indistinguishable from true alea. Then you use it as seed in random, which is less good: that one is a non-cryptographic PRNG, and its output may exhibit some structure which will not register in a statistical measurement tool, but might be exploited by an intelligent attacker. You should work with os.urandom() all along. To make things simple: choose an alphabet of length 64, e.g. letters (uppercase and lowercase), digits, and two extra punctuation characters (such as '+' and '/'). Then, for each password character, get one byte from os.urandom(), reduce the value modulo 64 (this is unbiased because 64 divides 256) and use the result as index in your chars array.

                  对于长度为 64 的字母表,每个字符的熵为 6 位(因为 26 = 64).因此,对于 13 个字符,您将获得 78 位的熵.这最终并不是在所有情况下都很强大,但已经非常强大(它可能会被以数月和数十亿美元计算的预算击败,而不仅仅是数百万).

                  With an alphabet of length 64, you get 6 bits of entropy per character (because 26 = 64). Thus, with 13 characters, you get 78 bits of entropy. This is not ultimately strong in all cases, but already very strong (it could be defeated with a budget which will be counted in months and billions of dollars, not mere millions).

                  这篇关于高质量、简单的随机密码生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:我*必须*将第三方凭据存储在我的数据库中.最好的办法? 下一篇:Python 3.2 中的蛮力脚本

                  相关文章

                  <i id='gCPwT'><tr id='gCPwT'><dt id='gCPwT'><q id='gCPwT'><span id='gCPwT'><b id='gCPwT'><form id='gCPwT'><ins id='gCPwT'></ins><ul id='gCPwT'></ul><sub id='gCPwT'></sub></form><legend id='gCPwT'></legend><bdo id='gCPwT'><pre id='gCPwT'><center id='gCPwT'></center></pre></bdo></b><th id='gCPwT'></th></span></q></dt></tr></i><div id='gCPwT'><tfoot id='gCPwT'></tfoot><dl id='gCPwT'><fieldset id='gCPwT'></fieldset></dl></div>
                • <small id='gCPwT'></small><noframes id='gCPwT'>

                    <bdo id='gCPwT'></bdo><ul id='gCPwT'></ul>
                  <tfoot id='gCPwT'></tfoot>
                  <legend id='gCPwT'><style id='gCPwT'><dir id='gCPwT'><q id='gCPwT'></q></dir></style></legend>