Cov txheej txheem:

Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Kev Txiav Txim Siab Software: 3 Kauj Ruam
Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Kev Txiav Txim Siab Software: 3 Kauj Ruam

Video: Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Kev Txiav Txim Siab Software: 3 Kauj Ruam

Video: Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Kev Txiav Txim Siab Software: 3 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Decryption Software
Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Decryption Software
Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Decryption Software
Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Decryption Software

Hauv Cov Lus Qhia Kuv yuav qhia koj li cas nrog qee qhov Python yooj yim, koj tuaj yeem khaws koj cov ntaub ntawv ruaj ntseg siv kev lag luam tus qauv AES.

Yuav tsum:

Nab hab sej 3.7

PyAesCrypt tsev qiv ntawv

- hashlib library

Yog tias koj tsis muaj cov tsev qiv ntawv no, koj tuaj yeem teeb tsa tau yooj yim los ntawm kev ntaus:

pip3 install hashlib

pip3 nruab PyAesCrypt

hauv lub davhlau ya nyob twg (lossis CMD)

Koj yuav tsum muaj cov no:

- random tsev qiv ntawv

- os lib

- lub tsev qiv ntawv

Kuv tab tom siv OS X, tab sis nws yuav tsum tsis muaj teeb meem ntau dhau, tshwj tsis yog rau cov lus qhia ntawm qhov sib tsoo hauv cov kab ntawv (OS X: /, Windows:)

Thov nco tseg: Vim tias muaj qee qhov tsis sib xws, qhov tsis txaus ntseeg hauv txoj cai tsis qhia rau qee yam. Yog li yuav tsis muaj qhov nkag rau hauv cov kab lus tso tawm, txawm li cas los xij lawv muaj nyob hauv Python cov ntaub ntawv kuv tau txuas nrog qhov kawg, thiab hauv cov duab uas tau muab tso rau. Tsuas yog tsis txhob coj tus lej ncaj qha los ntawm cov ntawv pom, vim nws yuav tsis ua haujlwm vim tsis muaj qhov nkag mus

Yog tias koj muaj txhua qhov kev cia siab tau teeb tsa, cia peb txav mus rau Kauj Ruam 1.

Kauj Ruam 1: Sau Cov Ntaub Ntawv Teeb

Sau Cov Ntaub Ntawv Teeb
Sau Cov Ntaub Ntawv Teeb
Sau Cov Ntaub Ntawv Teeb
Sau Cov Ntaub Ntawv Teeb
Sau Cov Ntaub Ntawv Teeb
Sau Cov Ntaub Ntawv Teeb
Sau Cov Ntaub Ntawv Teeb
Sau Cov Ntaub Ntawv Teeb

Ib qho ntawm cov xwm txheej uas ua rau kom muaj kev nyab xeeb yog kev siv hashes los tshuaj xyuas tus password. Cov ntaub ntawv teeb tsa (Kuv hu kuv li setupsafe.py) yog:

- Tsim cov ntawv tais ceev tseg thiab cov ntaub ntawv dag rau tus password

- Teeb tus password

- Teev tus lej naj npawb

- Hash tus password

Ua ntej tshaj, peb tab tom yuav ntshuam peb cov kev cia siab:

los ntawm sys ntshuam *

import os

ntshuam ntshuam

import hashlib

Tom ntej no peb yuav tsim cov ntawv tais ceev tseg rau lub tsev tus password hash thiab cov ntaub ntawv dummy:

sim: yog tias tsis os.path.exists ('desktop/safesetup'):

os.mkdir ('desktop/safesetup/')

tsuas yog OSError:

print ("Yuam kev tsim nplaub tshev")

Txoj cai no yuav tsim daim nplaub tshev hu ua safesetup (tshwj tsis yog nws twb muaj lawm).

Tom qab qhov no, peb yuav teeb tus password, thiab tsim tus lej tsis sib xws ntawm 1 txog 100 raws li peb txoj hauv kev mus rau cov ntaub ntawv dummy:

thoob ntiaj teb tus passwordpassword = argv [1].encode ('utf-8')

n = random.randint (1, 101)

Tam sim no peb muaj peb tus password thiab peb tus lej cov ntaub ntawv, peb tab tom tsim 99 cov ntaub ntawv dummy hauv kev ruaj ntseg, thiab ib daim ntawv tiag uas yuav muaj peb tus lej hash:

rau x hauv kab (101): yog (x! = n):

f = qhib (("desktop/safesetup/"+str (x)), "w+")

f.close ()

lwm tus:

password = hashlib.sha256 (password).hexdigest ()

f = qhib (("desktop/safesetup/"+str (x)), "w+")

f.write (password)

f.close ()

luam tawm (n)

Cov ntaub ntawv tiag tiag hu ua xijpeem integer n yog. Cov ntaub ntawv no muaj peb tus lej zais, tom qab tau siv lub sha256 algorithm (qhov hash algorithm tau siv dav hauv cryptocurrencies, tshwj xeeb tshaj yog Bitcoin).

Nco ntsoov tias n yog dab tsi (nws yuav luam tawm hauv lub console), vim nws tseem ceeb npaum li tus password.

Qhov ntawd yog txhua yam peb xav tau rau peb cov phiaj xwm teeb tsa, yog li tam sim no peb yuav txav mus rau qhov kev pabcuam encryption/decryption.

Kauj ruam 2: Cov Ntaub Ntawv Encryption/decryption

Cov ntaub ntawv Encryption/decryption
Cov ntaub ntawv Encryption/decryption
Cov ntaub ntawv Encryption/decryption
Cov ntaub ntawv Encryption/decryption
Cov ntaub ntawv Encryption/decryption
Cov ntaub ntawv Encryption/decryption

Kev teeb tsa ntu ntawm cov ntaub ntawv tseem ceeb ntshuam qhov kev cia siab, hashes tus lej nkag nkag, thiab khaws tus lej tiag tiag hash siv cov ntaub ntawv nkag mus.

Ua ntej, kev vam khom:

los ntawm sys ntshuam *ntshuam os

ntshuam pyAesCrypt

import hashlib

Tom ntej no, qhov hashing ntawm tus nkag lo lus zais:

password = argv [1].encode ('utf-8') password = hashlib.sha256 (password).hexdigest ()

Thaum kawg, tus hashed retrieval password:

file_key = str (argv [2]) hash = qhib (("desktop/safesetup/" + file_key), ("r +")). nyeem ()

Ntu ob ntawm cov ntaub ntawv encryption sib piv cov hashes, txiav txim siab qhov tseeb ntawm kev sib piv, thiab siv AESCrypt nab hab sej lub tsev qiv ntawv los encrypt lossis decrypt koj cov ntaub ntawv xaiv. Nov yog qhov loj me me ntawm cov cai, tab sis kuv yuav rhuav nws:

yog (lo lus zais == hash): luam tawm ("Tus lej lees paub")

bufferSize = 64 * 1024

ua haujlwm = str (cov tswv yim ("Puas yog koj tab tom nrhiav lossis zais cov ntaub ntawv? (r lossis e)"))

yog (ua haujlwm == 'r'):

file_name = str (cov tswv yim ("Cov ntaub ntawv mus muab tau:"))

pyAesCrypt.decryptFile ((file_name + ".aes"), file_name, password, bufferSize

os.remove ((file_name + ".aes"))

elif (kev ua haujlwm == 'e'):

file_name = str (input ("Cov ntaub ntawv rau encrypt:"))

pyAesCrypt.encryptFile (file_name, (file_name + ".aes"), password, bufferSize

os.remove (file_name)

lwm tus:

print ("Yuam kev: Cov ntaub ntawv tsis raug")

lwm tus:

print ("Kev tsis lees paub")

Thawj qhov yog cov lus txiav txim siab seb qhov hashed passwords zoo li cas. Yog tias lawv ua, nws tseem mus nug seb koj puas xav encrypt cov ntaub ntawv lossis khaws cov ntaub ntawv encrypted. Nyob ntawm koj lub tswv yim, nws yuav yog encrypt lossis decrypt cov ntaub ntawv muab. Thaum hais kom muab lub npe ntawm cov ntawv, nco ntsoov qhia txoj hauv kev tshwj tsis yog cov ntawv nyob hauv tib phau ntawv teev npe li qhov program python. Txoj haujlwm tshem tawm cov ntaub ntawv hauv nws lub xeev dhau los, hloov nws nrog cov ntaub ntawv encrypted.aes, lossis txiav txim siab nws thiab hloov nws nrog cov ntawv qub.

Yav tom ntej, kuv yuav hloov kho qhov no kom suav nrog lub ntsej muag paub siv Python OpenCV lub tsev qiv ntawv, tab sis tam sim no tus password yuav tsum txaus.

Kauj Ruam 3: Kev Ua Haujlwm ntawm Cov Ntaub Ntawv

Txhawm rau khiav cov ntaub ntawv teeb tsa, ua raws cov theem no:

1. Ntaus hauv lub davhlau ya nyob twg:

python3 directory/setupname.py lo lus zais (hloov cov npe, teeb tsa lub npe, thiab tus password nrog lawv cov txiaj ntsig tshwj xeeb)

2. Lub davhlau ya nyob twg yuav tso koj cov ntaub ntawv tus lej. Khaws qhov no.

Txhawm rau ua haujlwm encryption/decryption program, ua raws cov theem no:

1. Ntaus hauv lub davhlau ya nyob twg:

python3 directory/filename.py password filenumber (hloov cov npe, npe npe, tus password, thiab tus lej npe nrog lawv qhov txiaj ntsig zoo)

2. Lub davhlau ya nyob twg yuav lees lossis tsis lees paub koj tus password. Yog tias tsis lees paub, sim dua thiab xyuas kom tseeb tias koj ntaus hauv qhov raug. Thaum tau txais kev tso cai, lub davhlau ya nyob twg yuav nug koj yog tias koj xav kom encrypt cov ntaub ntawv lossis khaws cov ntawv. Txhawm rau encrypt cov ntaub ntawv, ntaus e, thiab khaws cov ntaub ntawv encrypted, ntaus r.

3. Tom qab ntawd koj yuav raug nug kom muab lub npe cov ntaub ntawv. Nco ntsoov muab cov npe ntawm cov ntaub ntawv nrog rau lub npe, thiab tseem ua cov ntaub ntawv txuas ntxiv. Txawm li cas los xij, yog tias koj tab tom lees cov ntaub ntawv, tsis txhob ntaus.aes ib feem ntawm qhov txuas ntxiv, vim tias tus lej nyiaj rau qhov ntawd.

4. Qhov kev zov me nyuam tom qab ntawd encrypts lossis decrypts cov ntaub ntawv muab, thiab rho tawm cov ntawv hauv nws lub xeev dhau los (khaws cov ntaub ntawv encrypted lossis decrypted).

Voila! Ua tsaug rau qhov ua kom deb li qhov qhia tau, Kuv paub nyeem cov lej qhia tsis yog qhov lom zem tshaj plaws. Cov ntaub ntawv nab nab tau muab zais rau hauv cov theem no, rau cov ntawm koj uas xav muab qhov no txhaj. Ib zaug ntxiv, ua tsaug rau kev nyeem ntawv, thiab kuv xav kom koj muaj hmoov zoo hauv koj txoj kev sau npe yav tom ntej.

Pom zoo: