起源:
影片下載,解析到一個網站時,發現其影片id是用AES加密過的,用的是這個函式庫。
解密很簡單的一句js程式碼:
t.video = CryptoJS.AES.decrypt(t.video, secret).toString(CryptoJS.enc.Utf8);
#原本想著簡單,找段python程式碼做解密是了,沒想到反覆嘗試,寫法五花八門多種多樣,就是解不出來,竟費去許多工夫!
如何簡單?我只實現驗證下面的字符串加解密:
# data = '-85297962_172051801'# key = '583a01a9ba901a3adda7252ebca42c09'# encrypt_data = 'U2FsdGVkX192df0Gxgia8s93zZp85f9m2nU1VIGU+RZQDtViB1LPBnE0CBWgVDBj'
1、Python Cryptography Toolkit (pycrypto)
加解密需要用到它,其網址是:
目前最新版本為2.6.1。如何安裝及其簡單Demo,其頁面上都 ,而其用法在網上一搜也到處都是,可就是不能解決我的問題,我想是我用錯了,但哪種才是對的哪!
crypto-js這個,應該用的是AES預設模式,AES.MODE_CBC。 js程式碼也是難懂,總是不停試不停試!
2、加密與解密
#直接上程式碼吧,它滿足了需求:
# coding=utf-8import base64from Crypto.Cipher import AESfrom Crypto import Randomfrom hashlib import md5 BLOCK_SIZE = AES.block_sizedef pad(data): length = BLOCK_SIZE - (len(data) % BLOCK_SIZE)return data + (chr(length) * length).encode()def unpad(data):return data[:-(data[-1] if type(data[-1]) == int else ord(data[-1]))]def bytes_to_key(my_data, salt, output=48):# extended from assert len(salt) == 8, len(salt) my_data += salt key = md5(my_data).digest() final_key = keywhile len(final_key)
同一個字符串,發現加密後的字符串,每次不盡相同。對AES沒多研究,挺覺奇怪!
3、打包與發布
若是只用到了Crypto一部分功能,例如我們用到的aes解密,則可以抽簡出來所需程式碼,以避免打入整個Crypto庫。
奇怪的是,引用_AES.pyd這個動態函式庫,引用路徑有問題。查閱資料,原來Crypto寫死了它的引用路徑,其頁碼有如此寫:
#ifdef IS_PY3Km = PyModule_Create(&moduledef);#elsem = Py_InitModule("Crypto.Cipher." _MODULE_STRING, modulemethods);#endif
而用py2exe打包抽取,其把Crypto\Cipher\_AES.pyd改名為Crypto.Cipher._AES.pyd文件,放與發布目錄下,令人頗長見識
以上是Python--AES加密與解密方法指導的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造

數組的同質性對性能的影響是雙重的:1)同質性允許編譯器優化內存訪問,提高性能;2)但限制了類型多樣性,可能導致效率低下。總之,選擇合適的數據結構至關重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,內存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

記事本++7.3.1
好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

WebStorm Mac版
好用的JavaScript開發工具