作者:灬段裝丶緈褔_998 | 来源:互联网 | 2023-09-10 12:39
python3安装Crypto.CipherimportAES问题背景:m3u8文件加密时,使用“fromCrypto.CipherimportAES”相关函数解密:#EXT-X-
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目录。
安装python3 pycryptodome模块
以下适用于在python3环境使用 Linux环境 pip3 install pycryptodome windos环境 pip3 install pycryptodome 进入python安装目录修改crypto目录名称为Crypto(只有windows环境需要修改) 默认安装的模块是放在site-packages下的 我的安装路径为: c:\python3.7.1\lib\site-packages\Crypto 或者 c:\python3.7.1\Lib\site-packages\Crypto
python导入crypto模块失败,提示:ImportError: DLL load failed: 找不到指定的模块
python导入crypto模块失败提示ImportError:DLL找不到指定的模块的原因:缺少crypto 库。
解决办法是:
第一步:上网查资料,需要安装python 的这个pycrypto库
(1)查询安装库,需要先安装pip
(2)安装pip的语句:
安装pip :建议安装Homebrew,然后brew install python
获取home-brew:命令行执行:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
命令行继续执行:brew install wget
这时候再去检查pip ,已经安装成功了
第二步:用pip安装库
(1)使用语句:pip3 install git+https://github.com/RNCryptor/RNCryptor-python.git#egg=rncryptor
(2)开始升级pip版本,执行pip3 install pymysql.还是报错,需要执行:pip3 install --upgrade pip.
第三步:用pip安装pycrypto库了
(1)执行安装语句:pip3 install git+https://github.com/RNCryptor/RNCryptor-python.git#egg=rncryptor.
(2)直接根据提示的日志,已经安装了这个库,用命令行执行:pip3 install Crypto,还是提示以上错误,继续执行:pip3 install pycrypto 还是提示以上错误。
直接执行卸载语句:pip3 uninstall pycrypto,提示卸载成功,再次执行:pip3 install pycrypto提示安装成功,重启pycharm 后运行项目。
如何为mac python安装pycrypto
解决方案一:安装Vs2008(实测)完全的无脑流,安装完问题直接解决。解决方案二:安装Vs2010(未测试)上次在电脑上装个Vs2010并不能像 vs2008那样直接解决问题,从网上找到如下解决方案,不知是否可行。
打开“\Lib\distutils\msvc9compiler.py”找到 toolskey = “VS%0.f0COMNTOOLS” % version,直接修改为 toolskey = ”VS100COMNTOOLS” 解决方案三:安装MinGW(实测)1、下载安装MinGW,下载地址为:http://sourceforge.net/projects/mingw/files/latest/download?source=files2、在MinGW的安装目录下找到bin文件夹,找到mingw32-make.exe,复制一份更名为make.exe3、把MinGW的路径添加到环境变量path中,比如我把MinGW安装到D:\MinGW\中,就把D:\MinGW\bin添加到path中;4、在\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\include” “-ID:\Program Files\Python27\include” “-ID:\Program Files\Python27\PC” -c../libdasm.c -o build\temp.win32-2.7\Release\..\libdasm.occ1.exe: error:unrecognized command line option ‘-mno-cygwin’error: command ‘gcc’ failed with exit status 1原因是gcc 4.6.x 以后不再接受-mno-cygwin为了解决这个问题需要修改\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-pathnames12/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 pycryptoReady to perform these actions:The following packages will be installed: pycrypto-2.0.1Get: [pypm.activestate.com] pycrypto 2.0.1-1Installing pycrypto-2.0.1PyPM 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 AESPADDING = '\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,是无法解密成功的。
Python使用Crypto/pyDes,DES并Base64编码
一、秘钥必须是8位 二、待加密的明文长度必须是8的倍数,不足则补空字符 为什么要说第二种,因为我在本地Python2.7通过pip安装Crypto始终安装不上. 遇到和我同样问题的朋友可以用该方式解决DES加解密