❶ cryptography python怎么安装
windows 版本:
http://www.voidspace.org.uk/python/moles.shtml#pycrypto
软件名:pycrypto-2.0.1.win32-py2.×
2.6版为exe文件,2.5版解压到 your2.5path/Lib/site-packages
linux 版本:
http://www.amk.ca/python/code/crypto.html
Manual:http://www.amk.ca/python/writing/pycrypt/
Linux版本安装需要 python setup.py build 和 python setup.py install
❷ 如何在virtualenv虚拟环境中安装mysql-python
接触过virtualenv后,想在这个虚拟环境中安装独立的开发环境。在安装MySQLdb时遇到错误
pc 09:09:30
File "/home/pc/work/VENV/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 50, in run_setup
lambda: execfile(
File "/home/pc/work/VENV/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 100, in run
return func()
File "/home/pc/work/VENV/py3/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 52, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 17, in <mole>
File "/tmp/easy_install-FtC77Z/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
File "/tmp/easy_install-FtC77Z/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
EnvironmentError: mysql_config not found
在国内的网上找了好长时间也没有找到办法,大多数是讲如何安装mysql-python的。先说一下解决过程吧
我是在ubuntu14上安装有virtualenv,在全局环境中安装了mysql-server,安装命令
sudo apt-get install mysql-server
后续过程都是在虚拟环境中进行的。我的是py3
开始找到要想使用mysql需要安装libmysqlclient-dev
安装过后在安装mysql-python还是出错
(py3)pc@pc-virtual-machine:~/work/VENV/py3/bin$ pip install mysql-python
Downloading/unpacking mysql-python
Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
Running setup.py (path:/home/pc/work/VENV/py3/build/mysql-python/setup.py) egg_info for package mysql-python
Installing collected packages: mysql-python
Running setup.py install for mysql-python
building '_mysql' extension
i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DTAOCRYPT_DISABLE_X86ASM -g -DNDEBUG
_mysql.c:29:20: fatal error: Python.h: No such file or directory
#include "Python.h"
^
compilation terminated.
error: command 'i686-linux-gnu-gcc' failed with exit status 1
Complete output from command /home/pc/work/VENV/py3/bin/python -c "import setuptools, tokenize;__file__='/home/pc/work/VENV/py3/build/mysql-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-V4wHKY-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/pc/work/VENV/py3/include/site/python2.7:
running install
running build
running build_py
creating build
creating build/lib.linux-i686-2.7
ing _mysql_exceptions.py -> build/lib.linux-i686-2.7
creating build/lib.linux-i686-2.7/MySQLdb
ing MySQLdb/__init__.py -> build/lib.linux-i686-2.7/MySQLdb
ing MySQLdb/converters.py -> build/lib.linux-i686-2.7/MySQLdb
ing MySQLdb/connections.py -> build/lib.linux-i686-2.7/MySQLdb
ing MySQLdb/cursors.py -> build/lib.linux-i686-2.7/MySQLdb
ing MySQLdb/release.py -> build/lib.linux-i686-2.7/MySQLdb
ing MySQLdb/times.py -> build/lib.linux-i686-2.7/MySQLdb
creating build/lib.linux-i686-2.7/MySQLdb/constants
ing MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.7/MySQLdb/constants
ing MySQLdb/constants/CR.py -> build/lib.linux-i686-2.7/MySQLdb/constants
ing MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.7/MySQLdb/constants
ing MySQLdb/constants/ER.py -> build/lib.linux-i686-2.7/MySQLdb/constants
ing MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.7/MySQLdb/constants
ing MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.7/MySQLdb/constants
ing MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-i686-2.7
i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DTAOCRYPT_DISABLE_X86ASM -g -DNDEBUG
_mysql.c:29:20: fatal error: Python.h: No such file or directory
#include "Python.h"
^
compilation terminated.
error: command 'i686-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /home/pc/work/VENV/py3/bin/python -c "import setuptools, tokenize;__file__='/home/pc/work/VENV/py3/build/mysql-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-V4wHKY-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/pc/work/VENV/py3/include/site/python2.7 failed with error code 1 in /home/pc/work/VENV/py3/build/mysql-python
Storing debug log for failure in /home/pc/.pip/pip.log
看到如果没有安装python-dev,需要安装这个就开始安装
sudo apt-get install python-dev
此时在安装mysql-python就可以了,所以安装步骤是
1 安装python-dev
sudo apt-get install python-dev
2 安装 libmysqlclient-dev
sudo apt-get install libmysqlclient-dev
3 安装mysql-python
pip install mysql-python
最后进行验证
(py3)pc@pc-virtual-machine:~/work/VENV/py3/bin$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "right", "credits" or "license" for more information.
>>> import MySQLdb
>>>
如果导入没有问题就说明导入成功了。
❸ perl怎么安装Crypt:SSLeay模块
由于要使用到https登录,所以要安装Crypt::SSLeay,
一、linux下安装
在Ubuntu的源里有libcrypt-ssleay-perl模块的,直接
$sudo apt-get install libcrypt-ssleay-perl
就OK,开始不知道,还要下载来自己安装,浪费时间,在此感谢CU上的dajun。
二、在win下安装
C:\Perl\bin>ppm-shell
ppm 4.01
Copyright (C) 2007 ActiveState Software Inc. All rights reserved.
ppm>install http://theoryx5.uwinnipeg.ca/ppms/Crypt-SSLeay.ppd (仅限perl5.8版本)
Downloading Crypt-SSLeay-0.53...done
Unpacking Crypt-SSLeay-0.53...done
Generating HTML for Crypt-SSLeay-0.53...done
Updating files in site area...done
Downloading Crypt-SSLeay-0.53 install script...done
Running Crypt-SSLeay-0.53 install script...
**************************************************************************
This software package uses strong cryptography, so even if it is created,
maintained and distributed from countries where it is legal to do this,
it falls under certain export/import and/or use restrictions in some
other parts of the world.
PLEASE REMEMBER THAT EXPORT/IMPORT AND/OR USE OF STRONG CRYPTOGRAPHY
SOFTWARE, PROVIDING CRYPTOGRAPHY HOOKS OR EVEN JUST COMMUNICATING
TECHNICAL DETAILS ABOUT CRYPTOGRAPHY SOFTWARE IS ILLEGAL IN SOME PARTS
OF THE WORLD. SO, WHEN YOU IMPORT THIS PACKAGE TO YOUR COUNTRY,
RE-DISTRIBUTE IT FROM THERE OR EVEN JUST EMAIL TECHNICAL SUGGESTIONS
OR EVEN SOURCE PATCHES TO THE AUTHOR OR OTHER PEOPLE YOU ARE STRONGLY
ADVISED TO PAY CLOSE ATTENTION TO ANY EXPORT/IMPORT AND/OR USE LAWS
WHICH APPLY TO YOU. THE AUTHORS OF OPENSSL ARE NOT LIABLE FOR ANY
VIOLATIONS YOU MAKE HERE. SO BE CAREFUL, IT IS YOUR RESPONSIBILITY.
CREDIT INFORMATION: This proct includes cryptographic software
written by Eric A. Young ([email protected]). This proct
includes software written by Tim J. Hudson ([email protected]).
**************************************************************************
Proceed with installation? [yes] yes
A of the needed library ssleay32.dll was found in
C:\WINDOWS\system32\ssleay32.dll. If this is compatible with the version (0.9.8a
)
used to compile the Perl mole, all that is needed to
complete the installation is to ensure
C:\WINDOWS\system32\ssleay32.dll is in your PATH environment variable.
Fetch ssleay32.dll? [no] no
Aborting download of ssleay32.dll.
done
13 files installed
ppm>
在linux下如果源没有此模块,就要自己去下载安装,不过好象我不成功,
n3tl04d@security:~/Crypt-SSLeay-0.57$ sudo apt-get install libssl-dev
n3tl04d@security:~$ wget http://www.perl.org/CPAN/authors/id/D/DL/DLAND/Crypt-SSLeay-0.57.tar.gz
--2009-08-16 17:07:49-- http://www.perl.org/CPAN/authors/id/D/DL/DLAND/Crypt-SSLeay-0.57.tar.gz
正在解析主机 www.perl.org... 207.171.7.63
正在连接 www.perl.org|207.171.7.63|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:http://www.cpan.org/authors/id/D/DL/DLAND/Crypt-SSLeay-0.57.tar.gz [跟随至新的 URL]
--2009-08-16 17:07:50-- http://www.cpan.org/authors/id/D/DL/DLAND/Crypt-SSLeay-0.57.tar.gz
正在解析主机 www.cpan.org... 66.39.76.93
正在连接 www.cpan.org|66.39.76.93|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 122980 (120K) [application/x-tar]
保存到‘Crypt-SSLeay-0.57.tar.gz’
100%[======================================>] 122,980 57.9K/s in 2.1s
2009-08-16 17:07:52 (57.9 KB/s) - `Crypt-SSLeay-0.57.tar.gz' 已经保存 [122980/122980]
n3tl04d@security:~$ tar -zxvf Crypt-SSLeay-0.57.tar.gz
Crypt-SSLeay-0.57
Crypt-SSLeay-0.57/t
Crypt-SSLeay-0.57/Changes
Crypt-SSLeay-0.57/lib
Crypt-SSLeay-0.57/certs
Crypt-SSLeay-0.57/MANIFEST
Crypt-SSLeay-0.57/TODO
Crypt-SSLeay-0.57/typemap
Crypt-SSLeay-0.57/MANIFEST.SKIP
Crypt-SSLeay-0.57/eg
Crypt-SSLeay-0.57/SSLeay.pm
Crypt-SSLeay-0.57/SSLeay.xs
Crypt-SSLeay-0.57/README
Crypt-SSLeay-0.57/Makefile.PL
Crypt-SSLeay-0.57/META.yml
Crypt-SSLeay-0.57/eg/lwp-ssl-test
Crypt-SSLeay-0.57/eg/net-ssl-test
Crypt-SSLeay-0.57/certs/ca-bundle.crt
Crypt-SSLeay-0.57/certs/notacakeynopass.pem
Crypt-SSLeay-0.57/certs/notacacert.pem
Crypt-SSLeay-0.57/lib/Crypt
Crypt-SSLeay-0.57/lib/Net
Crypt-SSLeay-0.57/lib/Net/SSL.pm
Crypt-SSLeay-0.57/lib/Crypt/SSLeay
Crypt-SSLeay-0.57/lib/Crypt/SSLeay/MainContext.pm
Crypt-SSLeay-0.57/lib/Crypt/SSLeay/Conn.pm
Crypt-SSLeay-0.57/lib/Crypt/SSLeay/X509.pm
Crypt-SSLeay-0.57/lib/Crypt/SSLeay/Err.pm
Crypt-SSLeay-0.57/lib/Crypt/SSLeay/CTX.pm
Crypt-SSLeay-0.57/t/00-basic.t
Crypt-SSLeay-0.57/t/02-live.t
Crypt-SSLeay-0.57/t/01-connect.t
n3tl04d@security:~$ cd Crypt-SSLeay-0.57/
n3tl04d@security:~/Crypt-SSLeay-0.57$ ls
certs eg Makefile.PL MANIFEST.SKIP README SSLeay.xs TODO
Changes lib MANIFEST META.yml SSLeay.pm t typemap
n3tl04d@security:~/Crypt-SSLeay-0.57$ sudo perl Makefile.pl
[sudo] password for n3tl04d:
Can't open perl script "Makefile.pl": 没有该文件或目录
n3tl04d@security:~/Crypt-SSLeay-0.57$ sudo perl Makefile.PL
========================================================================
No installed SSL libraries found in any of the following places.
/local
/local/ssl
/opt/ssl
/usr
/usr/local
/usr/local/ssl
/usr/local/openssl
You will have to either specify a directory location at the following
prompt, or rerun the Makefile.PL program and use the --lib switch
to specify the path. If the path in question is considered standard
on your platform, please consider filing a bug report in order to
have it taken into account in a subsequent version of Crypt::SSLeay.
This host looks like it is running Debian. Crypt::SSLeay needs to
be compiled with C headers that the libssl-dev package makes
available. Please install that package before trying to build this
mole. (You can always deinstall the package afterwards, once
Crypt::SSLeay has been built).
Which SSL install path do you want to use? /usr/local/ssl
/usr/local/ssl does not appear to be an SSL library installation, since
the required header files were not found. The build cannot proceed.
n3tl04d@security:~/Crypt-SSLeay-0.57$ sudo perl Makefile.PL
❹ 计算机丢失CRYPT32.dll,怎么重新安装
楼主你好,你可以重新下载一个crypt32dll.dll文件,然后按如下步骤操作:
一、解压后直接拷贝该文件到系统目录里:
1、Windows 95/98/Me系统,复制到C:WindowsSystem目录下。
2、Windows NT/2000系统,复制到C:WINNTSystem32目录下。
3、Windows XP/WIN7/Vista系统,复制到C:WindowsSystem32目录下。
4、如果您的系统是64位的请将文件复制到C:WindowsSysWOW64目录
二、打开"开始-运行-输入regsvr32 crypt32dll.dll",回车即可解决。
已上传并提供下载连接,可根据需要下载。
crypt32dll.dll下载地址:http://www.edowning.net/soft/86994.htm
❺ 如何为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,是无法解密成功的。
❻ “青锋爱分享”Springboot+Python之RSA加解密方案(RSA深入)二
本篇文章要结合上一节文章一起看。
青锋爱分享-RSA-Springboot+Python整合
码云搜索: 青锋 会有惊喜哦哦。
通过python生成的公钥私钥 格式PKCS1 。
生成pem格式如下:
私钥头(-----BEGIN RSA PRIVATE KEY-----)
私钥尾(-----END RSA PRIVATE KEY-----)
我需要将此私钥转换为DER编码的PKCS8未加密格式,以便与java服务器代码一起使用,特别是PKCS8EncodedKeySpec。我已经试过使用rsa和pkcs8命令的OpenSSL,如果有更简单的办法,没有特别需要使用openssl。
RSA私钥格式PKCS1和PKCS8相互转换
RSA公钥格式PKCS1和PKCS8相互转换
以下转换基于openssl命令的操作;
执行:openssl genrsa -out private.pem 1024
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlLm5++/wwSfq5KfY
H8q1AO/
Uo4OMcmoSz3IAp/7//ewIDAQAB
AoGBAJkMdvF+i9Kzc6YqMC0rfQJ3Zs+vFOtsbmQVAMnQ8JWBCJ1O8d/c60wRQgyb
lFCyO7VXOmoIJqX/Jr2aER8bFtG+
lOdOay7TkE45X/Wc7K9iZs2uuB7sylIvK/HVxxit6FGePa4RAkEA9e+VoAbxBv78
HyxRcStW+
n0UxgT55MPXWGdMRXUUOCNnMilaw/
HvK0IW3zpOgf/+/W565ROI/fjkR1qCD
rZJeHgqMWDlIUuR9+BdBAkAI8+
puQxMonRWTN+
-----END RSA PRIVATE KEY-----
执行:openssl pkcs8 -topk8 -inform PEM -in private.pem -outform pem -nocrypt -out pkcs8.pem
-----BEGIN PRIVATE KEY-----
+n
yHOOfV+XbBPsC7aWblIS3Pqv7/DBJ+/T
uaDSVA4K8Tmx22YC8PZ7HfAJ5/yVaaB2HmpSjg4xyahLPcgCn/v8WcxqDUh6VJ92
/
Q3fic/
+
nt0qVQJAOmMZ67caK+YHZ0M3Rp3adQgF+
//6OHlRQIElgect4wb
CbtfXWu9AfXNbTlXH39bnrlE4j9+
Yt1Zx5df0+
HLU0VEwSQa7rvmY=
-----END PRIVATE KEY-----
执行:openssl rsa -in pkcs8.pem -out pkcs1.pem
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlLm5++/wwSfq5KfY
H8q1AO/
Uo4OMcmoSz3IAp/7//ewIDAQAB
AoGBAJkMdvF+i9Kzc6YqMC0rfQJ3Zs+vFOtsbmQVAMnQ8JWBCJ1O8d/c60wRQgyb
lFCyO7VXOmoIJqX/Jr2aER8bFtG+
lOdOay7TkE45X/Wc7K9iZs2uuB7sylIvK/HVxxit6FGePa4RAkEA9e+VoAbxBv78
HyxRcStW+
n0UxgT55MPXWGdMRXUUOCNnMilaw/
HvK0IW3zpOgf/+/W565ROI/fjkR1qCD
rZJeHgqMWDlIUuR9+BdBAkAI8+
puQxMonRWTN+
-----END RSA PRIVATE KEY-----
可以看出结果和1是一致的;
执行:openssl rsa -in private.pem -pubout -out public.pem
-----BEGIN PUBLIC KEY-----
+Kosybacfp8hzjn1fl2wT
7Au2lm5SEtz6r+/wwSfq5KfYH8q1AO/
/7/FnMag1IelSfdronPBDxazp6
NUmQZITsYK6CsEl/ewIDAQAB
-----END PUBLIC KEY-----
5. 从pkcs8私钥中生成pkcs8公钥
执行:openssl rsa -in pkcs8.pem -pubout -out public_pkcs8.pem
-----BEGIN PUBLIC KEY-----
+Kosybacfp8hzjn1fl2wT
7Au2lm5SEtz6r+/wwSfq5KfYH8q1AO/
/7/FnMag1IelSfdronPBDxazp6
NUmQZITsYK6CsEl/ewIDAQAB
-----END PUBLIC KEY-----
可以看出结果和4是一样的;
执行:openssl rsa -pubin -in public.pem -RSAPublicKey_out
-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAOUubn4qizJtpx+nyHOOfV+XbBPsC7aWblIS3Pqv7/DBJ+rkp9gfyrUA
78L3YjASmmU1uupiY5dC7o/TuaDSVA4K8Tmx22YC8PZ7HfAJ5/yVaaB2HmpSjg4x
yahLPcgCn/=
-----END RSA PUBLIC KEY-----
openssl rsa -pubin -in public_pkcs8.pem -RSAPublicKey_out
-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAOUubn4qizJtpx+nyHOOfV+XbBPsC7aWblIS3Pqv7/DBJ+rkp9gfyrUA
78L3YjASmmU1uupiY5dC7o/TuaDSVA4K8Tmx22YC8PZ7HfAJ5/yVaaB2HmpSjg4x
yahLPcgCn/=
-----END RSA PUBLIC KEY-----
可以看出转换的结果是一致的;
执行:openssl rsa -RSAPublicKey_in -in pub_pkcs1.pem -pubout
-----BEGIN PUBLIC KEY-----
+Kosybacfp8hzjn1fl2wT
7Au2lm5SEtz6r+/wwSfq5KfYH8q1AO/
/7/FnMag1IelSfdronPBDxazp6
NUmQZITsYK6CsEl/ewIDAQAB
-----END PUBLIC KEY-----
可以看到和上面4,5的结果是一致的;
最后一点:
iOS上用的是pkcs8格式的公钥
openssl用的是pkcs1格式的公钥
知道私钥以后是可以导出公钥的,所以私钥一定要保证安全
知道公钥不可以导出私钥
解决方案针对是window电脑。
配置:SystemRoot/ System32 环境变量。
1、邮件我的电脑-选择下【属性】。
2、选择高级系统设置
3、选择【高级】-【环境变量】
4、双击打开path,进行编辑
5、 接着我们在这名字后面加【;System32】就可以了。
安装 Win64 OpenSSL,地址: http://slproweb.com/procts/Win32OpenSSL.html
下载后根据提示一步一步安装,安装完成后:
双击start.bat 启动
❼ python 中 crypto 的aes加密怎么使用
在刚开始知道这个模块的时候,连基本的Crypto模块的安装都花了很多很多时间来搞,也不知道什么情况反正是折腾很久了才安装起的,记得是包安装起来了,但使用的时候始终提示找不到Crypto.Cipher模块。然后怎么解决的呢?
一、把我的python换成了64位的,本来电脑就是64位的也不知道之前是啥情况安装成32位的了。(O(∩_∩)O哈哈~)
二、安装了VCForPython27.msi
三、在cmd中执行:
pip install pycrypto -i http://mirrors.aliyun.com/pypi/simple/1
经过上边儿的几个步骤,我是能够成功执行
from Crypto.Cipher import AES1
现在上一个实例代码:
# !/usr/bin/env python
# coding: utf-8
'''
'''
from Crypto.Cipher import AES
from binascii import b2a_hex, a2b_hex
class MyCrypt():
def __init__(self, key):
self.key = key
self.mode = AES.MODE_CBC
def myencrypt(self, text):
length = 16
count = len(text)
print count
if count < length:
add = length - count
text= text + ('\0' * add)
elif count > length:
add = (length -(count % length))
text= text + ('\0' * add)
# print len(text)
cryptor = AES.new(self.key, self.mode, b'0000000000000000')
self.ciphertext = cryptor.encrypt(text)
return b2a_hex(self.ciphertext)
def mydecrypt(self, text):
cryptor = AES.new(self.key, self.mode, b'0000000000000000')
plain_text = cryptor.decrypt(a2b_hex(text))
return plain_text.rstrip('\0')
if __name__ == '__main__':
mycrypt = MyCrypt('abcdefghjklmnopq')
e = mycrypt.myencrypt('hello,world!')
d = mycrypt.mydecrypt(e)
print e
print d
0414243
在cmd中执行结果:
❽ python mysqldb 安装问题
mysqldb只有python2.5版的,2.6的需要额外的东东,我也记不清了,不过有人把2.6对应的东东弄成一个exe了,直接运行就装上了,也不需要额外配置啥的,你留个邮箱啥的,我给你传过去吧。
import MySQldb?
还是MySQLdb?
l要大写L.
另外:_mysql.pyd是在python安装目录\Lib\site-packages下的
❾ 怎么解决.dll没有被指定在windows上运行
解决.dll没有被指定在windows上运行的方法如下:
1、网络搜索.dll前面的名称,并点击任意下载链接进入下载页面。