如何在Python应用程序中安装和使用OpenSSL库?

本文介绍了如何在Python应用中使用OpenSSL库。首先,通过pip在各种Linux发行版(如Ubuntu、Debian)及Windows系统上安装OpenSSL库。接着,展示了如何导入OpenSSL库,并打印SSL证书路径。通过创建一个名为testopenssl.py的Python脚本,导入OpenSSL并打印SSL库的版本信息来演示其用法。
摘要由CSDN通过智能技术生成

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
Install OpenSSL Python Lıbrary with Pip
Install OpenSSL Python Lıbrary with Pip
使用Pip安装OpenSSL Python库

使用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.

我们可以为基于debapt的发行版安装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.

我们可以为基于rpmyumdnf的发行版安装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
Print OpenSSL Library Version
Print OpenSSL Library Version
打印OpenSSL库版本
LEARN MORE  How To Generate Random Numbers In Linux?
了解更多如何在Linux中生成随机数?

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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值