在 Windows 上安装 Python 的密码学

7_R3X

我在 Windows 上创建了一个脚本来连接到远程 SSH 服务器。我已经成功安装了cryptographypynacl最后paramiko(花了我一整天的时间才弄清楚如何在 Windows 上成功安装它们)。

现在我运行脚本,它弹出一个错误,说 DLL 加载失败。该错误似乎与以下有关,libsodium但我无法确定要尝试加载哪个 DLL 以及从何处加载。为了更安全,我还安装了pysodium.

这是脚本:

自动化.py

import SSH

connection = ssh("10.10.65.100", "gerrit2", "gerrit@123")
print("Calling OpenShell")
connection.openShell()
print("Calling sendShell")
connection.sendShell("ls -l")
print("Calling process")
connection.process()
print("Calling closeConnection")
connection.closeConnection()

SSH.py

import threading, paramiko

class ssh:
    shell = None
    client = None
    transport = None

    def __init__(self, address, username, password):
        print("Connecting to server on ip", str(address) + ".")
        self.client = paramiko.client.SSHClient()
        self.client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
        self.client.connect(address, username=username, password=password, look_for_keys=False)
        self.transport = paramiko.Transport((address, 22))
        self.transport.connect(username=username, password=password)

        thread = threading.Thread(target=self.process)
        thread.daemon = True
        thread.start()

    def closeConnection(self):
        if(self.client != None):
            self.client.close()
            self.transport.close()

    def openShell(self):
        self.shell = self.client.invoke_shell()

    def sendShell(self, command):
        if(self.shell):
            self.shell.send(command + "\n")
        else:
            print("Shell not opened.")

    def process(self):
        global connection
        while True:
            # Print data when available
            if self.shell != None and self.shell.recv_ready():
                alldata = self.shell.recv(1024)
                while self.shell.recv_ready():
                    alldata += self.shell.recv(1024)
                strdata = str(alldata, "utf8")
                strdata.replace('\r', '')
                print(strdata, end = "")
                if(strdata.endswith("$ ")):
                    print("\n$ ", end = "")

这是错误:

> python automate.py

Traceback (most recent call last):
  File "automate.py", line 1, in <module>
    import SSH
  File "D:\Automate\SSH_Paramiko\SSH.py", line 1, in <module>
    import threading, paramiko
  File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko-2.4.0-py3.7.egg\paramiko\__init__.py", line 22, in <module>
  File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko-2.4.0-py3.7.egg\paramiko\transport.py", line 57, in <module>
  File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko-2.4.0-py3.7.egg\paramiko\ed25519key.py", line 22, in <module>
  File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\nacl\signing.py", line 19, in <module>
    import nacl.bindings
  File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\nacl\bindings\__init__.py", line 17, in <module>
    from nacl.bindings.crypto_box import (
  File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\nacl\bindings\crypto_box.py", line 18, in <module>
    from nacl._sodium import ffi, lib
ImportError: DLL load failed: The specified module could not be found.
7_R3X

经过大量的谷歌搜索,我终于偶然发现了这个正如对话中提到的,我卸载了之前的 pynacl 安装,从https://github.com/lmctv/pynacl/archive/v1.2.a0.reorder.zip下载了压缩源,从https://github下载了 libsodium 。 com/jedisct1/libsodium/releases/download/1.0.15/libsodium-1.0.15.tar.gz,将LIB环境变量设置D:\Users\prashant-gu\Downloads\libsodium-1.0.15\bin\x64\Release\v140\dynamic,最后使用这个下载的源安装pynacl

pip install .

现在它工作正常。

在安装过程中paramiko,我也碰巧从https://ci.cryptography.io/job/cryptography-support-jobs/job/openssl-release-1.1/下载了 OpenSSL ,并将 INCLUDE 环境变量设置D:\Users\prashant-gu\Downloads\openssl-1.1.0g-2015-x86_64\openssl-win64-2015\include为以成功安装在cryptography这恰好包成为一个依赖paramiko

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法安装PIP密码学

来自分类Dev

密码学:在python中加密

来自分类Dev

用python进行密码学

来自分类Dev

OSX上的密码学升级问题

来自分类Dev

在python 3中使用ASCII进行密码学

来自分类Dev

密码学安装在pip install`unicode`错误中失败

来自分类Dev

HKDF或PBKDF2用于生成对称加密密钥?(Python密码学)

来自分类Dev

Python 密码学 Fernet AES 加密换行符、缩进、回车

来自分类Dev

密码学

来自分类Dev

在Java 7u40上与applet一起使用的BouncyCastle密码学提供程序库

来自分类Dev

密码学-提交应用

来自分类Dev

密码学与散列

来自分类Dev

密码学代码混乱

来自分类Dev

在Windows 8上安装Python 2.7

来自分类Dev

尝试在Windows上的python中安装xgboost

来自分类Dev

在Windows上为Python安装Pillow

来自分类Dev

在Windows上安装Python模块的最佳做法

来自分类Dev

在Windows上使用Anaconda(Python)安装Pyomo

来自分类Dev

使用python在Windows上安装TTF字体

来自分类Dev

在Windows上安装python库cffi

来自分类Dev

无法在Windows 8上安装Python 2.7.8

来自分类Dev

无法在Windows,Python上安装特征

来自分类Dev

将bash指向Windows上安装的python

来自分类Dev

Windows 10上的Python Matplotlib安装问题

来自分类Dev

在Windows上安装预打包的Python模块

来自分类Dev

无法在Windows 8上安装Python 2.7.8

来自分类Dev

在Windows上安装python库cffi

来自分类Dev

无法在Windows上取消安装python 3.5

来自分类Dev

在Windows上安装Python模块paramiko