跳转到主要内容

scrypt密钥派生函数库的绑定

项目描述

这是一组Pythonscrypt密钥派生函数的绑定。

Latest Version https://anaconda.org/conda-forge/scrypt/badges/version.svg https://anaconda.org/conda-forge/scrypt/badges/downloads.svg

Scrypt在加密密码时很有用,因为它可以在加密和解密时指定一个最小时间量。例如,如果密码验证需要0.05秒,则用户在登录时不会注意到轻微的延迟,但进行数十亿密码的暴力搜索将花费相当多的时间。这与更传统的MD5或SHA系列等哈希函数形成对比,这些函数可以在廉价硬件上非常快速地实现。

安装

对于Debian和Ubuntu,请确保已安装以下包

$ sudo apt-get install build-essential libssl-dev python-dev

对于Fedora和RHEL衍生版,请确保已安装以下包

$ sudo yum install gcc openssl-devel python-devel

对于OSX,请执行以下操作

$ brew install openssl
$ export CFLAGS="-I$(brew --prefix openssl)/include $CFLAGS"
$ export LDFLAGS="-L$(brew --prefix openssl)/lib $LDFLAGS"

对于OSX,您还可以使用预编译的轮子。它们通过以下方式安装

$ pip install scrypt

对于Windows,请使用预编译的轮子。它们通过以下方式安装

$ pip install scrypt

对于Windows系统,在编译软件包时,需要从https://slproweb.com/products/Win32OpenSSL.html下载开发包。需要将其安装到C:OpenSSL-Win64。

如果您想安装最新但可能无法编译的版本,可以从这个仓库安装py-scrypt。

$ git clone https://github.com/holgern/py-scrypt.git
$ cd py-scrypt
$ python setup.py build

Become superuser (or use virtualenv):
# python setup.py install

Run tests after install:
$ python setup.py test

或者,您可以从PyPi上安装最新版本。

$ pip install scrypt

Anaconda Python发行版的用户可以直接从conda-forge频道获取预构建的Windows、Intel Linux或macOS/OSX二进制文件。可以通过以下方式实现:

$ conda install -c conda-forge scrypt

如果您想在Python 3环境中使用py-scrypt,只需使用Python 3解释器运行上述命令。Py-scrypt支持Python 2和3。

从版本0.6.0开始(PyPi上尚未提供),py-scrypt也支持PyPy。

变更日志

0.8.20

  • 通过向MANIFEST.in添加缺失的gettimeofday.c修复了问题#8

0.8.19

0.8.18

  • 添加python 3.9的wheel

0.8.17

  • 在Windows上为python 3.8添加add_dll_directory,因为importlib.util.find_spec不再搜索所有路径

0.8.16

  • 从RFC添加额外的测试向量(感谢@ChrisMacNaughton)

0.8.15

  • 修复缺失的导入

0.8.14

  • 修复imp弃用警告

0.8.13

  • 改进conda forge的构建

0.8.12

  • 添加SCRYPT_WINDOWS_LINK_LEGACY_OPENSSL环境变量,当设置时,链接openssl 1.0.2

0.8.11

  • 修复conda feedstock的构建

0.8.10

  • 修复拼写错误

0.8.9

  • 在Windows和openssl 1.1.1上使用静态libcrypto_static

0.8.8

  • 改进Windows的setup.py,支持openssl 1.0.2和1.1.1

0.8.7

  • 修复Windows的setup.py

0.8.6

  • 修复setup.py,版本0.8.5中scrypt无法导入

0.8.5

  • 修复MANIFEST.in

  • 将scrypt.py移动到自己的scrypt目录中,包含__init__.py

  • 修复osx wheel的openssl库路径

0.8.4

  • 将__version__添加到scrypt

  • 修复sha256.c中缺失的void

0.8.3

  • scrypt更新到1.2.1

  • 为python 3.6创建wheel

用法

对于加密/解密,库导出两个函数:encrypt和decrypt。

>>> import scrypt
>>> data = scrypt.encrypt('a secret message', 'password', maxtime=0.1) # This will take at least 0.1 seconds
>>> data[:20]
'scrypt\x00\r\x00\x00\x00\x08\x00\x00\x00\x01RX9H'
>>> scrypt.decrypt(data, 'password', maxtime=0.1) # This will also take at least 0.1 seconds
'a secret message'
>>> scrypt.decrypt(data, 'password', maxtime=0.05) # scrypt won't be able to decrypt this data fast enough
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
scrypt.error: decrypting file would take too long
>>> scrypt.decrypt(data, 'wrong password', maxtime=0.1) # scrypt will throw an exception if the password is incorrect
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
scrypt.error: password is incorrect

基于这些,可以使用以下函数创建一个简单的密码验证器:

def hash_password(password, maxtime=0.5, datalength=64):
    return scrypt.encrypt(os.urandom(datalength), password, maxtime=maxtime)

def verify_password(hashed_password, guessed_password, maxtime=0.5):
    try:
        scrypt.decrypt(hashed_password, guessed_password, maxtime)
        return True
    except scrypt.error:
        return False

但是,如果您想要输出是确定性的且大小恒定的,可以使用hash函数:

>>> import scrypt
>>> h1 = scrypt.hash('password', 'random salt')
>>> len(h1)  # The hash will be 64 bytes by default, but is overridable.
64
>>> h1[:10]
'\xfe\x87\xf3hS\tUo\xcd\xc8'
>>> h2 = scrypt.hash('password', 'random salt')
>>> h1 == h2 # The hash function is deterministic
True

致谢

Scrypt由Colin Percival创建,并以2-clause BSD许可证授权。由于scrypt通常不作为共享库构建,因此我已将当前最新版本的库源代码包含在本仓库中。当新版本到来时,我将更新这些源代码。

Bitbucket上的Kelvin Wong提供了使库在Mac OS X 10.6及更早版本上可用的更改,以及使库默认情况下更类似于scrypt命令行版本的更改。Kelvin还贡献了单元测试、大量的跨平台测试以及对hash函数的工作。

Bitbucket上的Burstaholic提供了使库在Windows上构建所需的更改。

用于为众多Python版本设置自动Windows构建的python-appveyor-demo仓库。

许可证

此库的许可证与scrypt相同;2-clause BSD。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源代码分发

scrypt-0.8.24.tar.gz (55.6 kB 查看哈希值)

上传时间 源代码

构建分发

scrypt-0.8.24-cp312-cp312-win_amd64.whl (40.3 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

scrypt-0.8.24-cp312-cp312-musllinux_1_1_x86_64.whl (1.3 MB 查看哈希值)

上传时间 CPython 3.12 musllinux: musl 1.1+ x86-64

scrypt-0.8.24-cp312-cp312-musllinux_1_1_i686.whl (1.3 MB 查看哈希值)

上传时间 CPython 3.12 musllinux: musl 1.1+ i686

scrypt-0.8.24-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

scrypt-0.8.24-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (945.3 kB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ i686

scrypt-0.8.24-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (960.0 kB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ ARM64

scrypt-0.8.24-cp312-cp312-macosx_10_9_x86_64.whl (1.2 MB 查看哈希值)

上传时间 CPython 3.12 macOS 10.9+ x86-64

scrypt-0.8.24-cp311-cp311-win_amd64.whl (40.3 kB 查看哈希值)

上传时间 CPython 3.11 Windows x86-64

scrypt-0.8.24-cp311-cp311-musllinux_1_1_x86_64.whl (1.3 MB 查看哈希值)

上传时间: CPython 3.11 musllinux: musl 1.1+ x86-64

scrypt-0.8.24-cp311-cp311-musllinux_1_1_i686.whl (1.3 MB 查看哈希值)

上传时间: CPython 3.11 musllinux: musl 1.1+ i686

scrypt-0.8.24-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ x86-64

scrypt-0.8.24-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (945.2 kB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ i686

scrypt-0.8.24-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (959.8 kB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ ARM64

scrypt-0.8.24-cp311-cp311-macosx_10_9_x86_64.whl (1.2 MB 查看哈希值)

上传时间: CPython 3.11 macOS 10.9+ x86-64

scrypt-0.8.24-cp310-cp310-win_amd64.whl (40.3 kB 查看哈希值)

上传时间: CPython 3.10 Windows x86-64

scrypt-0.8.24-cp310-cp310-musllinux_1_1_x86_64.whl (1.3 MB 查看哈希值)

上传时间: CPython 3.10 musllinux: musl 1.1+ x86-64

scrypt-0.8.24-cp310-cp310-musllinux_1_1_i686.whl (1.3 MB 查看哈希值)

上传时间: CPython 3.10 musllinux: musl 1.1+ i686

scrypt-0.8.24-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ x86-64

scrypt-0.8.24-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (945.2 kB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ i686

scrypt-0.8.24-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (959.8 kB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ ARM64

scrypt-0.8.24-cp310-cp310-macosx_10_9_x86_64.whl (1.2 MB 查看哈希值)

上传时间: CPython 3.10 macOS 10.9+ x86-64

scrypt-0.8.24-cp39-cp39-win_amd64.whl (40.3 kB 查看哈希值)

上传时间: CPython 3.9 Windows x86-64

scrypt-0.8.24-cp39-cp39-musllinux_1_1_x86_64.whl (1.3 MB 查看哈希值)

上传时间: CPython 3.9 musllinux: musl 1.1+ x86-64

scrypt-0.8.24-cp39-cp39-musllinux_1_1_i686.whl (1.2 MB 查看哈希值)

上传时间: CPython 3.9 musllinux: musl 1.1+ i686

scrypt-0.8.24-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB 查看哈希值)

上传时间: CPython 3.9 manylinux: glibc 2.17+ x86-64

scrypt-0.8.24-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (945.0 kB 查看哈希值)

上传时间: CPython 3.9 manylinux: glibc 2.17+ i686

scrypt-0.8.24-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (959.6 kB 查看哈希值)

上传时间: CPython 3.9 manylinux: glibc 2.17+ ARM64

scrypt-0.8.24-cp39-cp39-macosx_10_9_x86_64.whl (1.2 MB 查看哈希值)

上传时间: CPython 3.9 macOS 10.9+ x86-64

scrypt-0.8.24-cp38-cp38-win_amd64.whl (40.3 kB 查看哈希值)

上传于 CPython 3.8 Windows x86-64

scrypt-0.8.24-cp38-cp38-musllinux_1_1_x86_64.whl (1.3 MB 查看哈希值)

上传于 CPython 3.8 musllinux: musl 1.1+ x86-64

scrypt-0.8.24-cp38-cp38-musllinux_1_1_i686.whl (1.3 MB 查看哈希值)

上传于 CPython 3.8 musllinux: musl 1.1+ i686

scrypt-0.8.24-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ x86-64

scrypt-0.8.24-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (945.4 kB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ i686

scrypt-0.8.24-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (960.0 kB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ ARM64

scrypt-0.8.24-cp38-cp38-macosx_10_9_x86_64.whl (1.2 MB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ x86-64

scrypt-0.8.24-cp37-cp37m-win_amd64.whl (40.3 kB 查看哈希值)

上传于 CPython 3.7m Windows x86-64

scrypt-0.8.24-cp37-cp37m-musllinux_1_1_x86_64.whl (1.3 MB 查看哈希值)

上传于 CPython 3.7m musllinux: musl 1.1+ x86-64

scrypt-0.8.24-cp37-cp37m-musllinux_1_1_i686.whl (1.3 MB 查看哈希值)

上传于 CPython 3.7m musllinux: musl 1.1+ i686

scrypt-0.8.24-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.17+ x86-64

scrypt-0.8.24-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (945.4 kB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.17+ i686

scrypt-0.8.24-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (960.0 kB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.17+ ARM64

scrypt-0.8.24-cp37-cp37m-macosx_10_9_x86_64.whl (1.2 MB 查看哈希值)

上传于 CPython 3.7m macOS 10.9+ x86-64

scrypt-0.8.24-cp36-cp36m-win_amd64.whl (43.0 kB 查看哈希值)

上传于 CPython 3.6m Windows x86-64

scrypt-0.8.24-cp36-cp36m-musllinux_1_1_x86_64.whl (1.3 MB 查看哈希值)

上传于 CPython 3.6m musllinux: musl 1.1+ x86-64

scrypt-0.8.24-cp36-cp36m-musllinux_1_1_i686.whl (1.3 MB 查看哈希值)

上传于 CPython 3.6m musllinux: musl 1.1+ i686

scrypt-0.8.24-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB 查看哈希值)

上传于 CPython 3.6m manylinux: glibc 2.17+ x86-64

scrypt-0.8.24-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (945.4 kB 查看哈希值)

上传于 CPython 3.6m manylinux: glibc 2.17+ i686

scrypt-0.8.24-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (960.1 kB 查看哈希值)

上传于 CPython 3.6m manylinux: glibc 2.17+ ARM64

scrypt-0.8.24-cp36-cp36m-macosx_10_9_x86_64.whl (1.2 MB 查看哈希值)

上传于 CPython 3.6m macOS 10.9+ x86-64

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面