python密碼學(xué)實(shí)現(xiàn)文件加密教程
在Python中,可以在傳輸?shù)酵ㄐ磐ǖ乐凹用芎徒饷芪募?為此,您必須使用插件 PyCrypto .您可以使用下面給出的命令安裝此插件.
pip install pycrypto

代碼
用密碼保護(hù)器加密文件的程序代碼在下面提到 :
#?=================Other?Configuration================
#?Usages?:
usage?=?"usage:?%prog?[options]?"
#?Version
Version="%prog?0.0.1"
#?====================================================
#?Import?Modules
import?optparse,?sys,os
from?toolkit?import?processor?as?ps
def?main():
???parser?=?optparse.OptionParser(usage?=?usage,version?=?Version)
???parser.add_option(
??????'-i','--input',type?=?'string',dest?=?'inputfile',
??????help?=?"File?Input?Path?For?Encryption",?default?=?None)
???
???parser.add_option(
??????'-o','--output',type?=?"string",dest?=?'outputfile',
??????help?=?"File?Output?Path?For?Saving?Encrypter?Cipher",default?=?".")
???parser.add_option(
??????'-p','--password',type?=?"string",dest?=?'password',
??????help?=?"Provide?Password?For?Encrypting?File",default?=?None)
???parser.add_option(
??????'-p','--password',type?=?"string",dest?=?'password',
??????help?=?"Provide?Password?For?Encrypting?File",default?=?None)
???(options,?args)=?parser.parse_args()
???#?Input?Conditions?Checkings
???if?not?options.inputfile?or?not?os.path.isfile(options.inputfile):
??????print?"?[Error]?Please?Specify?Input?File?Path"
??????exit(0)
???if?not?options.outputfile?or?not?os.path.isdir(options.outputfile):
??????print?"?[Error]?Please?Specify?Output?Path"
??????exit(0)
???if?not?options.password:
??????print?"?[Error]?No?Password?Input"
??????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()您可以使用以下命令執(zhí)行加密過程以及密碼 :
python?pyfilecipher-encrypt.py?-i?file_path_for_encryption?-o?output_path?-p?password
輸出
當(dāng)您執(zhí)行上面給出的代碼時(shí),您可以觀察到以下輸出;

說明
T密碼是使用MD5哈希算法生成的,值存儲在Windows系統(tǒng)中的簡單安全備份文件中,其中包括顯示在下方和下方的值;

以上就是python密碼學(xué)實(shí)現(xiàn)文件加密教程的詳細(xì)內(nèi)容,更多關(guān)于python密碼學(xué)文件加密的資料請關(guān)注腳本之家其它相關(guān)文章!
- Python?hashlib模塊與哈希算法保護(hù)數(shù)據(jù)完整性教程
- Python基礎(chǔ)之hashlib模塊subprocess模塊logging模塊
- Python?HMAC模塊維護(hù)數(shù)據(jù)安全技術(shù)實(shí)例探索
- python借助ChatGPT讀取.env實(shí)現(xiàn)文件配置隔離保障私有數(shù)據(jù)安全
- Python3.10耙梳加密算法Encryption種類及開發(fā)場景
- python密碼學(xué)RSA密碼加密教程
- python密碼學(xué)各種加密模塊教程
- Python hashlib庫數(shù)據(jù)安全加密必備指南
相關(guān)文章
詳解Python開發(fā)語言中的基本數(shù)據(jù)類型
數(shù)據(jù)類型想必大家都知道是什么含義,指的是輸入數(shù)據(jù)的類型,任何數(shù)據(jù)都有明確的數(shù)據(jù)類型。本文主要和大家聊聊Python的三種基本數(shù)據(jù)類型,感興趣的可以了解一下2022-10-10
利用Python實(shí)現(xiàn)炸彈人游戲的完整代碼
這篇文章主要介紹了如何使用Python的Pygame庫實(shí)現(xiàn)一個炸彈人游戲,并對其進(jìn)行多方面的優(yōu)化,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-01-01
python3爬蟲獲取html內(nèi)容及各屬性值的方法
今天小編就為大家分享一篇python3爬蟲獲取html內(nèi)容及各屬性值的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12

