OpenSSL is popular security library used by a lot of products, applications, vendors. OpenSSL provides libraries for the most of the programming languages. Python is popular programming language too. We can use OpenSSL library in Python applications. In this tutorial we will develop an example application that uses OpenSSL Python Library and bindings.
OpenSSL是许多产品,应用程序,供应商使用的流行安全性库。 OpenSSL提供了大多数编程语言的库。 Python也是流行的编程语言。 我们可以在Python应用程序中使用OpenSSL库。 在本教程中,我们将开发一个使用OpenSSL Python库和绑定的示例应用程序。
使用Pip安装OpenSSL Python库 (Install OpenSSL Python Library with Pip)
We can use pip
install for all Linux distributions like Ubuntu, Debian, Mint, Kali, Fedora, CentOS, RedHat, etc. . We can also install OpenSSL Python Library in Windows Operating systems Windows 7, Windows 8, Windows 10, Windows Server 2008, Windows Server 2012, Windows Server 2016.
我们可以对所有Linux发行版使用pip
install,例如Ubuntu,Debian,Mint,Kali,Fedora,CentOS,RedHat等。 我们还可以在Windows操作系统Windows 7,Windows 8,Windows 10,Windows Server 2008,Windows Server 2012,Windows Server 2016中安装OpenSSL Python库。
$ pip install pyopenssl

使用Ubuntu,Debian,Mint,Kali安装OpenSSL Python库(Install OpenSSL Python Library with Ubuntu, Debian, Mint, Kali)
We can install OpenSSL python library for deb
or apt
based distributions like below.
我们可以为基于deb
或apt
的发行版安装OpenSSL python库,如下所示。
$ apt install python3-openssl
为CentOS,Fedora,RedHat安装OpenSSL Python库 (Install OpenSSL Python Lıbrary For CentOS, Fedora, RedHat)
We can install OpenSSL python libraries for rpm
or yum
or dnf
based distributions like below.
我们可以为基于rpm
或yum
或dnf
的发行版安装OpenSSL python库,如下所示。
$ yum install python3-pyOpenSSL.noarch
导入OpenSSL (Import OpenSSL)
In order to use OpenSSL library in our Python application we should import the OpenSSL library with the import
keyword like below.
为了在我们的Python应用程序中使用OpenSSL库,我们应该使用import
关键字导入OpenSSL库,如下所示。
from OpenSSL import SSL
打印OpenSSL库版本 (Print OpenSSL Library Version)
In this example we will print SSL Certificate Paths. SSL Certificate Paths are stored in the attribute _CERTIFICATE_PATH_LOCATIONS
. We will name the python application as testopenssl.py
and put the following code.
在此示例中,我们将打印SSL证书路径。 SSL证书路径存储在属性_CERTIFICATE_PATH_LOCATIONS
。 我们将python应用程序命名为testopenssl.py
并放置以下代码。
from OpenSSL import SSL
print SSL._CERTIFICATE_PATH_LOCATIONS
We run our python application like below.
我们如下运行python应用程序。
$ python testopenssl.py

翻译自: https://www.poftut.com/install-use-openssl-library-python-applications/