小编Chr*_*ris的帖子

python SystemRandom/os.urandom是否总有足够的熵来获得良好的加密

我有一个密码生成器:

import random, string

def gen_pass():
    foo = random.SystemRandom()
    length = 64
    chars = string.letters + string.digits
    return ''.join(foo.choice(chars) for _ in xrange(length))
Run Code Online (Sandbox Code Playgroud)

根据文档,SystemRandom使用os.urandom,它使用/ dev/urandom来丢弃随机的cryto位.在Linux中,您可以从/ dev/urandom或/ dev/random获取随机位,它们都使用内核可以获得的任何熵.可以使用tail/proc/sys/kernel/random/entropy_avail检查可用的熵量,这将返回如下数字:129.可用的熵越多./ dev/urandom和/ dev/random之间的区别在于/ dev/random只会在entropy_avail足够高(如至少60)时吐出位,而/ dev/urandom总是吐出位.文档说/ dev/urandom对加密有好处,你只需要使用/ dev/random来获得ssl证书等.

我的问题是gen_pass是否适合制作强大的加密级密码?如果我尽快调用此函数,我会在某个时刻停止获取强大的cryto位,因为熵池已经耗尽了吗?

这个问题也可能是为什么的/ dev/urandom的总是产生强烈cryto位不在乎entropy_avail?

有可能设计/ dev/urandom使其带宽受到可以猜测与熵量相关的周期数的限制,但这是猜测,我无法找到答案.

这也是我的第一个stackoverflow问题所以请批评我.我担心当知道答案的人可能知道背景时,我给了很多背景.

谢谢

更新

我写了一些代码来查看熵池,同时/dev/urandom从中读取:

import subprocess
import time

from pygooglechart import Chart
from pygooglechart import SimpleLineChart
from pygooglechart import Axis

def check_entropy():
    arg = ['cat', '/proc/sys/kernel/random/entropy_avail']
    ps = subprocess.Popen(arg,stdout=subprocess.PIPE)
    return int(ps.communicate()[0])

def run(number_of_tests,resolution,entropy = []):
    i …
Run Code Online (Sandbox Code Playgroud)

python linux random cryptography generator

21
推荐指数
1
解决办法
6376
查看次数

如何使ghostscript从postscript文件输出单个特定页面作为png?

我正在尝试将ghostscript用于其预期目的,以解释postscript文件和输出png.我想要一个命令,将单个特定页面从多页ps文件转换为单个png.我已经在infile是pdf文件的情况下完成了这个,但是当infile是ps时却没有.

此行将ps转换为由连接的png文件组成的文件.

gs -dSAFER -dBATCH -sDEVICE=png256 -r96x96 -sOutputFile=out.png in.ps

这将从pdf中获取单个特定页面并将其转换为png.

gs -q -dSAFER -dBATCH -dFirstPage=2 -dLastPage=2 -sDEVICE=png256 -SOut=fileout.png in.pdf

简单地将dFirstPage=标志放在后脚本输入案例中什么都不做.输出与标志不存在的输出相同.

linux postscript ghostscript

4
推荐指数
2
解决办法
4081
查看次数