當前位置:首頁 » 編程語言 » python安裝pycrypto

python安裝pycrypto

發布時間: 2023-08-08 03:37:06

1. 如何為mac python安裝pycrypto

解決方案一:安裝Vs2008(實測)
完全的無腦流,安裝完問題直接解決。
解決方案二:安裝Vs2010(未測試)
上次在電腦上裝個Vs2010並不能像 vs2008那樣直接解決問題,從網上找到如下解決方案,不知是否可行。
打開「<python安裝目錄>\Lib\distutils\msvc9compiler.py」
找到 toolskey = 「VS%0.f0COMNTOOLS」 % version,直接修改為 toolskey = 」VS100COMNTOOLS」
解決方案三:安裝MinGW(實測)
1、下載安裝MinGW,下載地址為:http://sourceforge.net/projects/mingw/files/latest/download?source=files
2、在MinGW的安裝目錄下找到bin文件夾,找到mingw32-make.exe,復制一份更名為make.exe
3、把MinGW的路徑添加到環境變數path中,比如我把MinGW安裝到D:\MinGW\中,就把D:\MinGW\bin添加到path中;
4、在<python安裝目錄>\distutils增加文件distutils.cfg,在文件里輸入
[build]
compiler=mingw32
保存;
5、執行原先的模塊安裝,發現還是報錯,報錯內容為:error: command 』gcc』 failed: No such file or directory 解決方案是將D:\MinGW\lib再添加到PATH中。
6、如果安裝過程中出現 error: Could not find 『openssl.exe』 則直接到http://pypi.python.org/pypi/pyOpenSSL/0.13 下載安裝即可。
再次執行時安裝模塊時,發現如下錯誤:
D:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall 「-ID:\Program Files\Python27\inc
lude」 「-ID:\Program Files\Python27\include」 「-ID:\Program Files\Python27\PC」 -c
../libdasm.c -o build\temp.win32-2.7\Release\..\libdasm.o
cc1.exe: error:unrecognized command line option 『-mno-cygwin』
error: command 『gcc』 failed with exit status 1
原因是gcc 4.6.x 以後不再接受-mno-cygwin為了解決這個問題需要修改<python安裝目錄>\distutils\cygwinccompiler.py文件。找到:
self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
compiler_so='gcc -mno-cygwin -mdll -O -Wall',
compiler_cxx='g++ -mno-cygwin -O -Wall',
linker_exe='gcc',
linker_so='%s -mno-cygwin %s %s'
% (self.linker_dll, shared_option,
entry_point))
修改為:
self.set_executables(compiler='gcc -O -Wall',
compiler_so='gcc -mdll -O -Wall',
compiler_cxx='g++ -mno-cygwin -O -Wall',
linker_exe='gcc',
linker_so='%s -mno-cygwin %s %s'
% (self.linker_dll, shared_option,
entry_point))
講了三個解決方案,安裝visualstudio太龐大的,沒有試,於是就嘗試第三種方法。其中openssl.exe的錯誤沒有碰到,應該是已經有了,而distutils.cfg文件的目錄在python2.7下面有點不一樣,在Python27\Lib\distutils下面。一直到最後個修改項,最終錯誤是:
error: expected 『=』, 『,』, 『;』, 『asm』 or 『__attribute__』 before 『PyInt_AsUnsignedLongLongMask』
沒有解決。
中間有個警告,在cygwin中使用dos style的path,設置path CYGWIN=nodosfilewarning 來規避
cygwin warning:
MS-DOS style path detected: C:\cygwin\home\ADMINI~1\hadoop\/build/native
Preferred POSIX equivalent is: /home/ADMINI~1/hadoop/build/native
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
12/02/13 10:34:53 INFO namenode.NameNode: STARTUP_MSG:
python setup.py install build --compiler=mingw32
這個命令嘗試也不行。
在這個url:http://stackoverflow.com/questions/1687283/why-cant-i-just-install-the-pycrypto,國際友人介紹用PyPM來安裝,由於要另外安裝工具,沒有嘗試:
You may use PyPM to install (pre-built binary package of) pycrypto:
C:> pypm install pycrypto
Ready to perform these actions:
The following packages will be installed:
pycrypto-2.0.1
Get: [pypm.activestate.com] pycrypto 2.0.1-1
Installing pycrypto-2.0.1
PyPM can be installed by installing ActivePython.http://www.activestate.com/activepython/
後來在這里http://lili-xiang.iteye.com/blog/1796640,看到有預編譯好的版本用來安裝,在地址http://www.voidspace.org.uk/downloads/pycrypto26/pycrypto-2.6.win-amd64-py3.2.exe下載PyCrypto 2.6 for Python 3.2 64bit,隨後安裝成功,可以在Komodo IDE 7中使用了。測試代碼是這里的:http://ddkangfu.blog.51cto.com/311989/484801
但是例子的代碼是跑不起來的,因為aes加密中,cbc模式下是還有個iv參數的,修改成這樣
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
PADDING = '\0'
pad_it = lambda s: s+(16 - len(s)%16)*PADDING
if __name__ == "__main__":
key = '1234567890123456'
data = 'qwertyuiopasdfgh'
obj = AES.new(key, AES.MODE_CBC, data)
#obj = AES.new(key, AES.MODE_ECB)
crypt = obj.encrypt(data)
print crypt
#obj2 = AES.new(key, AES.MODE_ECB)
obj2 = AES.new(key, AES.MODE_CBC, data)
recovery = obj2.decrypt(crypt)
print recovery
才可以正常運行,如果使用ECB模式,就不用最後一個iv參數的。這里使用加密源data作為iv參數是沒有意思的,正式使用的時候肯定會另外定義的字元串,記得iv長度要是16位的倍數。代碼里還要注意obj2,不能重復使用第一個obj,在加密過程中obj已經改變了,如果不充生成obj2,是無法解密成功的。

2. python 利用Crypto進行ECB 加密

windows下使用AES時安裝pycryptodome 模塊,pip install pycryptodome

linux 下使用AES時安裝pycrypto模塊,pip install pycrypto

```

from Crypto.Cipherimport AES

from binasciiimport b2a_hex, a2b_hex

from Cryptoimport Random

import base64

import json

class AesEncry(object):

        # aes秘鑰 ,可根據自身需要手動生成

     宴旁   key ="aes_keysaes_keysaes_keys"  

        def encrypt(self, data):

                data = json.mps(data)

                mode = AES.MODE_ECB

                padding =lambda s: s + (16 -len(s) %16) *chr(16 -len(s) %16)

                cryptos = AES.new(self.key.encode("utf-8"), mode)

                cipher_text = cryptos.encrypt(padding(data).encode("utf-8"))

                return base64.b64encode(cipher_text).decode("utf-8")

        def decrypt(self, data):

                cryptos = AES.new(self.key.encode("型祥握utf-8"), AES.MODE_ECB)

                decrpytBytes = base64.b64decode(data)

         卜慶       meg = cryptos.decrypt(decrpytBytes).decode('utf-8')

                return meg[:-ord(meg[-1])]

aes_encry_util = AesEncry()

#明文

data ="mypwd_test"

#加密

encry_data = aes_encry_util.encrypt(data)

print(encry_data)

# 對密文進行解密

decry_data = aes_encry_util.decrypt(encry_data)

print(decry_data)

```

如上便完成了利用python進行AES的ECB加密

3. python pycrypto 怎麼安裝

1. windwos系統下

由於需要編譯源碼,需要安裝相應的編譯器

Python 2.7 : Microsoft Visual C++ Compiler for Python 2.7 (網址:aka.ms/vcpython27)

sudoapt-getinstall-ypython-pycryptopp

4. python 預編譯pycrypto怎麼安裝

進入Python官網(www.python.org),把滑鼠移動到「download"按鈕上,會出現選擇版本界面,可以選擇2.x或者3.x的,進入下載頁面,點擊安裝文件進行下載,然後雙擊下載得到的安裝文件即可完成安裝。

5. python3 安裝Crypto.Cipher import AES

問題背景:

m3u8文件加密時,使用「from Crypto.Cipher import AES」相關函敗乎數解密:

#EXT-X-KEY 記錄了加密的方式,一般是AES-128以及加密的KEY信息

出現問題:

from Crypto.Cipher import AES

pip install Crypto

出錯

解決辦法:

安裝crypto庫(首字母c是小寫)

pip install crypto

進入python的庫管理位置,site-packages文件夾,找到crypto,將其首字母c改為大寫

判斷是否解決的方式:

from Crypto.Cipher import AES

不會報錯,說明成功。

備註:

如果在C:\Python36\Lib\site-packages\Crypto目錄下沒有找到:\Cipher目錄。

可以嘗試安裝pycryptodome庫察氏悉 或 pycrypto庫:

pip install pycryptodome

pip install pycrypto (安裝這個庫,基本會失敗核跡,會報錯)

6. centos中pycrypto模塊的安裝

如果已經成功安裝pycrypto依然找不到Crypto模塊,那麼就將Python安裝路徑下的C:Python27Libsite-packages的crypto文件夾改為大寫即可!!

熱點內容
衛士相當於現在什麼配置 發布:2025-02-06 17:05:04 瀏覽:409
項目編譯慢 發布:2025-02-06 16:53:48 瀏覽:382
python處理excel文件 發布:2025-02-06 16:36:09 瀏覽:442
演算法相對定位 發布:2025-02-06 16:32:42 瀏覽:727
java程序的編譯和執行 發布:2025-02-06 16:21:45 瀏覽:420
什麼是淘寶帳號和密碼 發布:2025-02-06 16:21:36 瀏覽:497
解壓前面簽 發布:2025-02-06 16:02:00 瀏覽:326
華碩訪問點 發布:2025-02-06 15:56:57 瀏覽:333
excel拼接sql 發布:2025-02-06 15:50:10 瀏覽:503
加密手機直播 發布:2025-02-06 15:49:31 瀏覽:537