where to get and install crypto.dll on 64 bit Windows

Note. This is not a Visual Studio issue, but rather incompatible dll versions. The steps below reproduce the problem, because when starting in Visual Studio in debug mode, exceptions occur when exceptions occur. If you just run it, the generated exception is handled elsewhere and the program works fine. But since I spend a lot of time in debug mode, I would rather fix this problem.

When debugging, I want to be able to enter the modules that I added to my virtual environment in Visual Studio. I get a "library not found" error, which I cannot fix. Here are the steps:

  1. In Visual Studio, create a new Python application.
  2. Create a virtual environment for this application (Python 3.6, 64 bit).
  3. pip install twiliointo your virtual environment. You will get the following output.

...

   ----- Installing 'twilio' -----
Collecting twilio
  Using cached twilio-6.10.5-py2.py3-none-any.whl
Collecting pytz (from twilio)
  Using cached pytz-2018.3-py2.py3-none-any.whl
Collecting six (from twilio)
  Using cached six-1.11.0-py2.py3-none-any.whl
Collecting PyJWT>=1.4.2 (from twilio)
  Using cached PyJWT-1.6.0-py2.py3-none-any.whl
Collecting requests>=2.0.0; python_version >= "3.0" (from twilio)
  Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting pysocks; python_version >= "3.0" (from twilio)
  Using cached PySocks-1.6.8.tar.gz
Collecting certifi>=2017.4.17 (from requests>=2.0.0; python_version >= "3.0"->twilio)
  Using cached certifi-2018.1.18-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests>=2.0.0; python_version >= "3.0"->twilio)
  Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests>=2.0.0; python_version >= "3.0"->twilio)
  Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests>=2.0.0; python_version >= "3.0"->twilio)
  Using cached idna-2.6-py2.py3-none-any.whl
Installing collected packages: pytz, six, PyJWT, certifi, chardet, urllib3, idna, requests, pysocks, twilio
  Running setup.py install for pysocks: started
    Running setup.py install for pysocks: finished with status 'done'
Successfully installed PyJWT-1.6.0 certifi-2018.1.18 chardet-3.0.4 idna-2.6 pysocks-1.6.8 pytz-2018.3 requests-2.18.4 six-1.11.0 twilio-6.10.5 urllib3-1.22
----- Successfully installed 'twilio' -----
  1. Add the following line to the top of your .py file:

    from twilio.rest import Client

  2. In Visual Studio, go to Tools> Options> Python> Debugging. Make sure the Enable Python standard library debugging check box is selected.

  3. Launch the app. You get the following error:

ModuleNotFoundError: no module named "OpenSSL"

  1. pip install pyopenssl You will get the following output:

...

----- Installing 'pyopenssl' -----
Collecting pyopenssl
  Using cached pyOpenSSL-17.5.0-py2.py3-none-any.whl
Requirement already satisfied: six>=1.5.2 in c:\users\x\source\repos\pythonapplication9\pythonapplication9\env\lib\site-packages (from pyopenssl)
Collecting cryptography>=2.1.4 (from pyopenssl)
  Using cached cryptography-2.1.4-cp36-cp36m-win_amd64.whl
Requirement already satisfied: idna>=2.1 in c:\users\x\source\repos\pythonapplication9\pythonapplication9\env\lib\site-packages (from cryptography>=2.1.4->pyopenssl)
Collecting cffi>=1.7; platform_python_implementation != "PyPy" (from cryptography>=2.1.4->pyopenssl)
  Using cached cffi-1.11.5-cp36-cp36m-win_amd64.whl
Collecting asn1crypto>=0.21.0 (from cryptography>=2.1.4->pyopenssl)
  Using cached asn1crypto-0.24.0-py2.py3-none-any.whl
Collecting pycparser (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography>=2.1.4->pyopenssl)
  Using cached pycparser-2.18.tar.gz
Installing collected packages: pycparser, cffi, asn1crypto, cryptography, pyopenssl
  Running setup.py install for pycparser: started
    Running setup.py install for pycparser: finished with status 'done'
Successfully installed asn1crypto-0.24.0 cffi-1.11.5 cryptography-2.1.4 pycparser-2.18 pyopenssl-17.5.0
----- Successfully installed 'pyopenssl' -----
  1. Launch the app. You get the following error:

    asn1crypto._ffi.LibraryNotFoundError: The library libcrypto could not be found

Error _big_num_ctypes.pyin file named _big_num_ctypes.pyin asn1crypto. The line of code where it is thrown:

libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')
if not libcrypto_path:
    raise LibraryNotFoundError('The library libcrypto could not be found')

Update: I was asked to provide a full reverse trace. I changed the code to print it:

import unittest
import traceback

class Test_test1(unittest.TestCase):
    def test_A(self):
        try:
            from twilio.rest import Client
        except Exception as e:
            print('foo')
            foo = traceback.extract_stack()
            traceback.print_exc(e)

if __name__ == '__main__':
    unittest.main()

As before, the import line throws an exception, but the exception is not caught, and the lines in the "except" clause are never executed from the twilio.rest import client

2: - @Prateek @user8212173. . , , crypto.dll . , , :

  1. Win64 OpenSSL v1.1.0j https://slproweb.com/products/Win32OpenSSL.html ( https://wiki.openssl.org/index.php/Binaries). crypto.dll.
  2. crypto.dll http://www.dlldownloader.com/crypto-dll/ ( @user8212173) ( 32- ) . "ImportError: DLL:% 1 Win32", , crypto.dll ( 64- python 64- ). , Windows Python, . , 64- crypto.dll?
+14
4

, crypto.dll. DLL .

, pip install crypto python, dll.

ctypes.util.find_library dll windows.

: find_library() ctypes

.

find_library('l2gpstore')
>>'C:\\WINDOWS\\system32\\l2gpstore.dll'
find_library('java')
>>'C:\\Program Files\\Java\\jdk-9.0.4\\bin\\java.dll'

, OpenSSL libcrypto

OpenSSL

OpenSSL

git, GitHub https://github.com/openssl/openssl. ( ) GitHub. , .

libcrypto OpenSSL

: GitHub

libcrypto ( , ): X.509, SSL/TLS, .

, , crypto.dll , .

, .

:

, , .

OpenSSL 1.1.0 1.0.2

13 2018 - OpenSSL 1.1.0 . 1.0.2 (LTS) 1.1.1 (LTS) . 1.1.1. . OpenSSL . -

1.0.2 Github, crypto.h, . OpenSSL DLL, libeay32 libcrypto

, asn1crypto . , asn1crypto. , pipenv.

, .

DLL , DLLdownloader


OpenSSL asn1crypto OpenSSL 1.0.2, , , , crypto.h.

!

+5

, _big_num_ctypes.py. , Visual Studio, crypto.dll. . , _big_num_ctypes.py:

#imports
from ctypes.util import find_library
.
.
from .._ffi import LibraryNotFoundError, FFIEngineError

try:
# On Python 2, the unicode string here may raise a UnicodeDecodeError as it
# tries to join a bytestring path to the unicode name "crypto"
    libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')
    if not libcrypto_path:
        raise LibraryNotFoundError('The library libcrypto could not be found')
.
.
except (AttributeError):
    raise FFIEngineError('Error initializing ctypes')

:

C:\>cd "C:\ProgramData\Anaconda3\Lib\site-packages\asn1crypto\_perf"
C:\ProgramData\Anaconda3\Lib\site-packages\asn1crypto\_perf>python _big_num_ctypes.py

Traceback :

Traceback (most recent call last):
  File "_big_num_ctypes.py", line 27, in <module>
    from .._ffi import LibraryNotFoundError, FFIEngineError
ValueError: attempted relative import beyond top-level package

, .ffi :

from asn1crypto._ffi import LibraryNotFoundError, FFIEngineError

libcrypto:

asn1crypto._ffi.LibraryNotFoundError: The library libcrypto could not be found

, dll crypto C:\Windows\System32 / SYSWOW64 ( 64-)

libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')

find_library - . , docs. - , None.

>>> from ctypes.util import find_library
>>> print(find_library("c"))
None

crypto.dll, . , . :

 >>> find_library('crypto')
'C:\\windows\\system32\\crypto.dll'

python _big_num_ctypes.py Traceback:

    Traceback (most recent call last):
  File "_big_num_ctypes.py", line 37, in <module>
    libcrypto = CDLL(libcrypto_path)
  File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

, 32- DLL 64- Python , , . , 32- Python 3.6 py -3.6-32 _big_num_ctypes.py. , .

, Crypto 32- ? answer .

, Pycryptodome Crypto, Crypto. , , , MS Visual Studio 2015 (Community Edition) C/++ . , ++ MS Visual Studio .

, crypto.dll Pycryptodome, , . OpenSSL Twilio. , MS Visual Studio , .

unittest, :

#Output

.
----------------------------------------------------------------------
Ran 1 test in 0.771s

OK
+3

Windows 10, Visual Studio Community 2017,

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\site-packages\asn1crypto_perf_big_num_ctypes.py :

libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')

:

libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'libcrypto')

.

libcrypto.dll C:\Windows\System32\

0

?

'crypto' 'libcrypto' '_big_num_ctypes.py'.

.

asn1crypto._ffi.LibraryNotFoundError: The library libcrypto could not be found.

But I ran into another error "OpenSSL.SSL.WantReadError".

(virtualenv path) \ Lib \ site-packages \ OpenSSL \ SSL.py

Line 1620

error = _lib.SSL_get_error(ssl, result)
if error == _lib.SSL_ERROR_WANT_READ:
    raise WantReadError()

I installed OpenSSL as both 1.0.2 and 1.1.1.

0
source

Source: https://habr.com/ru/post/1694921/


All Articles