当我用python编写status = gpg.decrypt_file(f, passphrase='password', output='output.txt')
时。
我可以解密文件。在
当我写password='password'
status = gpg.decrypt_file(f, passphrase=password, output='output.txt')
我也可以解密文件。在
但当我写作的时候
ff = open("4.txt",'rb')
temp = ff.readline()
password = temp[0:len(temp)-2]
status = gpg.decrypt_file(f, passphrase=password, output='output.txt')
我无法解密文件,因为temp
是password\r\n
,所以password
是“密码”
谢谢。在
这样密码短语就可以工作了,因为只有那些没有换行符的字符。在
^{pr2}$首先,注意
temp[0:len(temp)-2]
更习惯地写成temp[:-2]
。在此表达式获取序列
temp
的最后两个项目。在由于
temp
是一个字节序列,因此总是删除该序列的最后两个字节。在这不是从输入行中删去换行符的可靠方法。在
相反,在文本模式下打开文件,您将得到标准化的换行符和文本输入。然后,使用
str
内置方法按字符操作它。在相关问题 更多 >
编程相关推荐