Python加密怎样实现,工具和方法是什么
在实际应用中,我们有时候会遇到“Python加密怎样实现,工具和方法是什么”这样的问题,我们该怎样来处理呢?下文给大家介绍了解决方法,希望这篇“Python加密怎样实现,工具和方法是什么”文章能帮助大家解决问题。
在Python中,可以在传输到通信通道之前加密和解密文件.为此,您必须使用插件PyCrypto.您可以使用下面给出的命令安装此插件.
到此这篇关于“Python加密怎样实现,工具和方法是什么”的文章就介绍到这了,更多相关Python加密怎样实现,工具和方法是什么内容,欢迎关注博信技术资讯频道,小编将为大家输出更多高质量的实用文章!
在Python中,可以在传输到通信通道之前加密和解密文件.为此,您必须使用插件PyCrypto.您可以使用下面给出的命令安装此插件.
pip install pycrypto
代码
用密码保护器加密文件的程序代码在下面提到 :
#=================OtherConfiguration================ #Usages: usage="usage:%prog[options]" #Version Version="%prog0.0.1" #==================================================== #ImportModules importoptparse,sys,os fromtoolkitimportprocessorasps defmain(): parser=optparse.OptionParser(usage=usage,version=Version) parser.add_option( '-i','--input',type='string',dest='inputfile', help="FileInputPathForEncryption",default=None) parser.add_option( '-o','--output',type="string",dest='outputfile', help="FileOutputPathForSavingEncrypterCipher",default=".") parser.add_option( '-p','--password',type="string",dest='password', help="ProvidePasswordForEncryptingFile",default=None) parser.add_option( '-p','--password',type="string",dest='password', help="ProvidePasswordForEncryptingFile",default=None) (options,args)=parser.parse_args() #InputConditionsCheckings ifnotoptions.inputfileornotos.path.isfile(options.inputfile): print"[Error]PleaseSpecifyInputFilePath" exit(0) ifnotoptions.outputfileornotos.path.isdir(options.outputfile): print"[Error]PleaseSpecifyOutputPath" exit(0) ifnotoptions.password: print"[Error]NoPasswordInput" exit(0) inputfile=options.inputfile outputfile=os.path.join( options.outputfile,os.path.basename(options.inputfile).split('.')[0]+'.ssb') password=options.password base=os.path.basename(inputfile).split('.')[1] work="E" ps.FileCipher(inputfile,outputfile,password,work) return if__name__=='__main__': main()
您可以使用以下命令执行加密过程以及密码 :
pythonpyfilecipher-encrypt.py-ifile_path_for_encryption-ooutput_path-ppassword
输出
当您执行上面给出的代码时,您可以观察到以下输出;
说明
T密码是使用MD5哈希算法生成的,值存储在Windows系统中的简单安全备份文件中,其中包括显示在下方和下方的值;
到此这篇关于“Python加密怎样实现,工具和方法是什么”的文章就介绍到这了,更多相关Python加密怎样实现,工具和方法是什么内容,欢迎关注博信技术资讯频道,小编将为大家输出更多高质量的实用文章!
版权声明
本文仅代表作者观点,不代表博信信息网立场。