标签: python-cryptography

错误:无法为使用 PEP 517 且无法直接安装的加密构建轮子

pip 为加密包构建轮子时出现错误。

错误:

错误

LINK : fatal error LNK1181: cannot open input file 'libssl.lib'
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x86\\link.exe' failed with exit status 1181
  ----------------------------------------
  ERROR: Failed building wheel for cryptography
  Running setup.py clean for cryptography
Failed to build cryptography
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly
Run Code Online (Sandbox Code Playgroud)

我已经安装OpenSSL和设置环境变量中所建议的这个帖子却问题依旧。我的设置细节:

  • 系统 - Windows 10
  • 蟒蛇 - 3.8
  • 点子 - 19.3.1

python cryptography pip python-cryptography

40
推荐指数
8
解决办法
7万
查看次数

Paramiko:"FutureWarning:CTR模式需要计数器参数"

我试图在Python2中使用Paramiko通过私有SSH密钥通过SFTP传输文件,但它显示此警告:

/usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py:141: 
FutureWarning: CTR mode needs counter parameter, not IV   self._cipher = factory.new(key, *args, **kwargs)
Run Code Online (Sandbox Code Playgroud)

实际上它将文件发送到服务器,但有人可以解释一下这个警告意味着什么吗?

这是我的代码:

t = paramiko.Transport((host, port))
key = paramiko.RSAKey.from_private_key_file("/path/to/key.ssh") 
t.connect(username="username",password=None, pkey=key)

sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(source, destination)

sftp.close()
t.close()
Run Code Online (Sandbox Code Playgroud)

python sftp warnings paramiko python-cryptography

16
推荐指数
1
解决办法
2万
查看次数

加密AssertionError:对不起,但这个版本只支持100个命名组

我正在pip installtravis上安装几个python包,

language: python
python:
- '2.7'
install:
- pip install -r requirements/env.txt
Run Code Online (Sandbox Code Playgroud)

一切都很好,但今天我开始得到以下错误:

 Running setup.py install for cryptography
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-hKwMR3/cryptography/setup.py", line 334, in <module>
    **keywords_with_side_effects(sys.argv)
  File "/opt/python/2.7.9/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/setuptools/dist.py", line 269, in __init__
    _Distribution.__init__(self,attrs)
  File "/opt/python/2.7.9/lib/python2.7/distutils/dist.py", line 287, in __init__
    self.finalize_options()
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/setuptools/dist.py", line 325, in finalize_options
    ep.load()(self, ep.name, value)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/cffi/setuptools_ext.py", line 181, in cffi_modules
    add_cffi_module(dist, …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 travis-ci python-cryptography

15
推荐指数
1
解决办法
2829
查看次数

Pipenv 安装在加密包上失败:“禁用 PEP 517 处理无效”错误

在没有意识到这一点的情况下,我已经使用密码学包好几个月了,没有出现问题,但突然间它无法构建并且导致我的项目的开发停止。

事实证明,密码学是我的 Pipfile: 中其他包之一的依赖项apns2。正如我所说,它运行良好,但我的环境中肯定发生了一些变化。这是我的 Pipfile,只隔离了那个包:

[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[requires]
python_version = "3.7.9"

[packages]

apns2 = "*"

[dev-packages]
Run Code Online (Sandbox Code Playgroud)

这失败了。我使用pipenv(最新版本 2020.11.15),所以当我现在运行它时,这是输出:

# pipenv install
Creating a virtualenv for this project...
Pipfile: /Users/dylan/Dev/RideHare/server/Pipfile
Using /Users/dylan/.pyenv/versions/3.7.9/bin/python3.7m (3.7.9) to create virtualenv...
? Creating virtual environment...created virtual environment CPython3.7.9.final.0-64 in 502ms
  creator CPython3Posix(dest=/Users/dylan/.local/share/virtualenvs/server-2uc2X-TS, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/dylan/Library/Application Support/virtualenv)
    added seed packages: pip==20.2.2, setuptools==51.0.0, wheel==0.35.1
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

? Successfully created virtual …
Run Code Online (Sandbox Code Playgroud)

python pip python-3.x python-cryptography pipenv

11
推荐指数
3
解决办法
6822
查看次数

CryptographyDeprecationWarning:Python 核心团队不再支持 Python 3.6

我将系统从 python 2 升级到 python 3,现在当我运行代码时:

from cryptography.hazmat.backends import default_backend
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

/usr/local/lib/python3.6/site-packages/paramiko/transport.py:33:
CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python 
core team. Therefore, support for it is deprecated in cryptography and will be 
removed in a future release.
Run Code Online (Sandbox Code Playgroud)

如何解决呢?

python python-3.x python-cryptography

10
推荐指数
2
解决办法
6万
查看次数

Docker:在 alpine linux 发行版上安装 python 加密

我对 Docker 和部署周期有点陌生。

我有一个 Django 应用程序,我们想用 uWSGI 将它部署到 docker 容器。实际上部署完美地工作了几个星期,但现在它完全报告错误......

错误接缝与密码学包有关:

build/temp.linux-x86_64-3.6/_openssl.c:52862:10: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
build/temp.linux-x86_64-3.6/_openssl.c: In function '_cffi_f_SSL_set_options':
build/temp.linux-x86_64-3.6/_openssl.c:52895:14: warning: conversion to 'long int' from 'long unsigned int' may change the sign of the result [-Wsign-conversion]
   { result = SSL_set_options(x0, x1); }
              ^~~~~~~~~~~~~~~
build/temp.linux-x86_64-3.6/_openssl.c:52895:14: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
error: command 'gcc' failed …
Run Code Online (Sandbox Code Playgroud)

uwsgi docker dockerfile alpine-linux python-cryptography

8
推荐指数
2
解决办法
9869
查看次数

如何/如何使用 python 和加密模块生成 PKCS#12 文件?

如何/如何使用 python 和加密模块生成 PKCS#12 文件?

使用上述模块为私钥生成 .pem 文件的内容非常简单:

keyPEMBytes = privateKey.private_bytes(
    encoding=serialization.Encoding.PEM,
    format=serialization.PrivateFormat.TraditionalOpenSSL,
    encryption_algorithm=serialization.NoEncryption())
Run Code Online (Sandbox Code Playgroud)

也很容易为关联的证书生成 .cer/.pem 文件的内容:

certBytes = certificate.public_bytes(encoding=serialization.Encoding.PEM)
Run Code Online (Sandbox Code Playgroud)

但是我需要将它们(和它们的链)整合到一个 .p12(PKCS12 文件)中。所述模块记录了如何解析/使用 PKCS12 格式,但没有(我能找到的)关于如何生成它们的信息。

不过,我对 PKI 内容的理解是偶然的,所以也许我只是没有在文档中搜索正确的关键字?

可以使用 Linux 在命令行中创建 .p12 文件

openssl pkcs12 -export -out myIdentity.p12 -inkey myPrivKey.pem -in myCert.crt -certfile myCertChain.crt
Run Code Online (Sandbox Code Playgroud)

所以我可以用 subprocess/cmd 来包装这样的调用,并用临时文件/管道来处理。不过,我希望将其全部保存在内存/python 中。

是否有我应该考虑的不同的 python TLS 库,可以做到这一点?

python pkcs#12 python-3.x python-cryptography

8
推荐指数
1
解决办法
3681
查看次数

类型错误:from_buffer() 无法返回 unicode 对象的地址

在将工具更新到 python3 时,我在 MacOS 上遇到了这个问题。

print(args.secret)
h = hmac.HMAC(args.secret.decode("hex"),hashes.SHA512(),backend=default_backend())
Run Code Online (Sandbox Code Playgroud)

输出

39830c786a16

h = hmac.HMAC(hex(int(args.secret, 16)), hashes.SHA512(), backend=default_backend())
  File "/usr/local/lib/python3.7/site-packages/cryptography/hazmat/primitives/hmac.py", line 31, in __init__
    self._ctx = self._backend.create_hmac_ctx(key, self.algorithm)
  File "/usr/local/lib/python3.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 202, in create_hmac_ctx
    return _HMACContext(self, key, algorithm)
  File "/usr/local/lib/python3.7/site-packages/cryptography/hazmat/backends/openssl/hmac.py", line 34, in __init__
    key_ptr = self._backend._ffi.from_buffer(key)
TypeError: from_buffer() cannot return the address of a unicode object

Run Code Online (Sandbox Code Playgroud)

可能是加密包的问题。一些答案建议重新安装加密包及其依赖项。(cffi、pycparser、六)

pip3 list
Run Code Online (Sandbox Code Playgroud)
six             1.14.0
cryptography    2.8
pycparser       2.19
cffi            1.13.2
Run Code Online (Sandbox Code Playgroud)

还是不行。有人遇到过类似的问题吗?

cryptography python-3.x python-cffi python-cryptography

8
推荐指数
0
解决办法
2万
查看次数

在 Apple Silicon M1 Mac 上安装加密

帮助!我正在尝试在我的 m1 上安装加密。我知道我可以在 rosetta 模式下运行终端,但我想知道是否有办法不这样做。

输出:

    ERROR: Command errored out with exit status 1:
     command: /opt/homebrew/opt/python@3.9/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/tmpl4sga84k
         cwd: /private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-install-jko4b562/cryptography_7b1bbc9ece2f481a8e8e9ea03b1a0030
    Complete output (55 lines):
    
        =============================DEBUG ASSISTANCE=============================
        If you are seeing a compilation error please try the following steps to
        successfully install cryptography:
        1) Upgrade to the latest pip and try again. This will fix errors for most
           users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
        2) Read https://cryptography.io/en/latest/installation.html for specific
           instructions for your platform.
        3) Check our frequently asked questions for more information:
           https://cryptography.io/en/latest/faq.html …
Run Code Online (Sandbox Code Playgroud)

python-cryptography apple-silicon apple-m1

8
推荐指数
4
解决办法
3428
查看次数

是否可以为以后的会话保存 fernet 密钥?

我是 python 的新手,我正在开发一个加密文本字符串的程序,然后将其保存到一个文件中。当我在同一个会话中加密然后解密它时,我的程序运行良好。我想做的是:加密文件,然后关闭程序,稍后再返回并解密。我不知道密码学模块是如何工作的,但判断它是如何被称为“密钥”的,我认为这对安全很重要,但我不知道。当我尝试将 fernet 密钥保存到文本文件时,它会显示一条错误消息。当我尝试解密在前一个会话中加密的消息时,它显示 4 个引用加密模块的错误。最后,我想知道是否可以使用加密模块在会话之间解密数据。如果不,有没有其他方法可以完成这项任务?谢谢你的帮助。这是我的代码:

from cryptography.fernet import Fernet
key = Fernet.generate_key()
f = Fernet(key)
sel = input("Would you like to encrypt or decrypt? (1 = encrypt, 2 = decrypt) ")
if sel == 1:
    inp = raw_input("Enter Text: ")  # Type here
    encoded = f.encrypt(inp)
    a, b = encoded[:len(encoded)/2], encoded[len(encoded)/2:]
    print ("YOUR PASSWORD: ")
    print b
    file = open('password.txt', 'w')
    file.write(a)
elif sel == 2:
    inp = raw_input("Enter Password: ")
    file = open('password.txt', 'r')
    a = file.readline() …
Run Code Online (Sandbox Code Playgroud)

python encryption cryptography python-2.7 python-cryptography

7
推荐指数
1
解决办法
4108
查看次数