DeriveHelper 脚本
项目描述
派生助手
DeriveHelper 是一个帮助 KDF 的脚本。KDF (Key Derivation Function) 是一种从密码中导出加密密钥的函数。DeriveHelper 允许创建密码、盐和派生加密密钥。DeriveHelper 当前支持以下 KDF:
Bcrypt Scrypt PBKDF2HMAC Argon2I Argon2ID
派生用法
import derivehelper
password = derivehelper.create_pw(64) # Create a 64 character long password
salt = derivehelper.create_pw(32) # Create a 32 character long salt
'''
The Derive class takes in 3 arguments.
1. The password to derive the key from.
2. The salt to use for the KDF.
3. The KDF to use.
'''
d = derivehelper.Derive(password, salt, derivehelper.KDF.BCRYPT)
'''
To actually derive the key, call the derive() method.
The Bcrypt KDF by default, generates a key of which is 32 bytes long, and 100 rounds. The byte value can be changed
by passing in an integer for the first parameter. You can also get a base64 encoded version by passing in encode=True
'''
print(d.derive()) # b'H\x15\xbb\xb7\xcaQ\xee\xa1\xfe-\xa51\xca\x8d\x12\xfe5\xd2h!\xd9\xeaV\xc6\xfbp3L\x98(`\x97'
# For a 56 byte key
print(d.derive(56)) # b'H\x1c\x15\xca\xbb \xb7l\xcaIQ\x9c\xee8\xa1\x98\xfe\xa3-\xf9\xa5\xf61&\xca\x8b\x8d\t\x12\x17\xfeN57\xd2hh\xa4!\x0f\xd9s\xeaHV\x08\xc6\xb3\xfb\xe9p\xc03\x91L\xe9'
# For base64 encoded output.
print(d.derive(56, encode=True)) # 'SBwVyrsgt2zKSVGc7jihmP6jLfml9jEmyouNCRIX/k41N9JoaKQhD9lz6khWCMaz++lwwDORTOk='
- 可选参数
import derivehelper
password = derivehelper.create_pw(64)
salt = derivehelper.create_pw(32)
d = derivehelper.Derive(password, salt, derivehelper.KDF.BCRYPT)
'''
The derive() method has another optional argument called extra_args, of which is a tuple.
This is where you can pass in KDF-specific additional options. In this example since I'm
using bcrypt, I can pass in a different rounds value via this extra_args argument.
I will pass in 150 for 150 rounds. It is 100 by default.
'''
print(d.derive(extra_args=(150,))) # b'B\x089\x96\xbbf|\xfe\xb0\xd9\x93+\x9f\x88\x00\xfbFW\xd2\x8f>\xd2\xb10\x1f\xff\x94>\xf5\xffV#'
'''
PBKDF2HMAC also has support for this argument. It will control the iteration value.
By default it is 150,000. But can be overridden.
'''
d = derivehelper.Derive(password, salt, derivehelper.KDF.PBKDF2HMAC)
# Using 250,000 iterations.
d.derive(extra_args=(250000,)) # b'\xcd\x15\xd6~\xceC\xa2r\xcf\x93KCS;E\x13\xac\x9b\x7f\xdf\xe7Tt\x89H\x0c\x84\xe4\xc1\xdau\x94'
哈希使用
- 自定义 using() 功能即将推出!
- 支持的哈希函数:Argon2ID、Argon2I、Argon2D、Bcrypt、Bcrypt_SHA256、PBKDF2-SHA1、PBKDF2-SHA256、PBKDF2-SHA512、SHA256-crypt、SHA512-crypt、Scrypt。
import derivehelper
password = derivehelper.create_pw(32) # Create 32 char password
'''
To utilize the hashing functions of derivehelper, instantiate the Hash class.
The Hash class takes in 1 parameter, the password (labeled "secret").
'''
h = derivehelper.Hash(password)
# To get the hash value, call the method of which corresponds to the hash you want.
# For argon2id
print(h.argon2id()) # $argon2id$v=19$m=102400,t=2,p=8$P0foXQuB8D4npDRGqLW21g$vGpZF/z9erC3sVFcZls2Gw
# For bcrypt
print(h.bcrypt()) # $2b$12$oov7QnFVNxKSi/6AgxsfMudfX3NaC.sqmVMqEHozDd2.hgTJrMslO
# For PBKDF2-SHA256
print(h.pbkdf2_sha256()) # $pbkdf2-sha256$29000$x3hPScm5915LqTVm7J0Tgg$P9/FNmie9ONydtCzcII9BPA/7XD5NHqnixvP9NFWoVQ
# For SHA256-crypt
print(h.sha256_crypt()) # $5$rounds=535000$vOEY9PcYv.fTIgAB$/NOB/DAqAvo/SQe6ckxVOJOqWahlosBItvuQAItVVf.
重要笔记
-
- 使用 Argon2I 或 Argon2ID KDF 时,它们都只支持 16 字节的固定盐大小。可以使用 urandom 或 create_pw 函数简单地创建此类。只需传入 16 字节/长度。
-
- Scrypt、Argon2ID 和 Argon2I 是唯一不支持 extra_args 参数的 KDF。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
derivedhelper-0.5.tar.gz
(5.1 kB
查看哈希)
内置分布
derivedhelper-0.5-py3-none-any.whl
(5.1 kB
查看哈希)
关
derivedhelper -0.5.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 04ce6891b5e502fc78dc9e30e1061dfe965d3f16a91eecbb137297d4e3d63ed2 |
|
MD5 | 4349b18ee8ec5739d383ae73e5cae99c |
|
布莱克2-256 | 511a24719a0707dc1bf07cdbd4521fb1063957632ee62ca7b534d9cddcd88ac9 |
关
derivedhelper -0.5-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 8145c650ae33c86bf6de5886a43560dcb7889718a679bd2c0fade2ad6d0f1123 |
|
MD5 | 6b1fa1d510205879ddbd1834b0cfc11d |
|
布莱克2-256 | 5dadb8de33b9c8d0220195058c14089b42bb4dafeca8c9dcdccbfeadfe9dcf00 |