Windows BCrypt 加密安全随机数C扩展,与secrets接口完全一致
Project description
token-gen-win
Windows平台专用高性能C扩展,基于系统原生 BCrypt API 实现加密安全随机数,完整复刻Python标准库 secrets 常用接口,性能优于原生Python实现。
平台限制
仅支持 Windows 系统 Linux / macOS 无系统BCrypt依赖库,无法编译、安装。
功能列表
完全对齐标准库 secrets 接口:
token_bytes():生成随机字节串token_hex():生成十六进制随机令牌token_urlsafe():生成URL安全随机令牌randbelow():生成指定上界安全随机整数randbits():生成指定比特位随机数choice():从序列随机选取元素shuffle():原地随机打乱序列
安装方式
pip install token-gen
快速使用
import token_gen
# 生成各类安全令牌
print(token_gen.token_urlsafe())
print(token_gen.token_hex(16))
print(token_gen.token_bytes(32))
# 随机数工具
print(token_gen.randbelow(1000))
print(token_gen.randbits(12))
# 序列操作
lst = [1,2,3,4,5]
print(token_gen.choice(lst))
token_gen.shuffle(lst)
print(lst)
注意事项
- 基于栈分配实现,不支持超大长度随机数生成(建议单次长度不超过1024),避免栈溢出
- 长期后台运行存在轻微BCrypt句柄残留,短期脚本使用无任何影响
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
secrets_plus-0.2.0.tar.gz
(5.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file secrets_plus-0.2.0.tar.gz.
File metadata
- Download URL: secrets_plus-0.2.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50322809d3c5dea95582145b5e9044e5d724956c3bee1f1c2ff2e4618b077054
|
|
| MD5 |
e9e1b02f60214ed64a1eb88368f5e994
|
|
| BLAKE2b-256 |
9d922edbd7a20c06b3ea67ed3476f659b9be55dd4be54b3f3362092f9bf9a6ab
|
File details
Details for the file secrets_plus-0.2.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: secrets_plus-0.2.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 9.5 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78ffa7b9001caa71f1a9e84fcbd3fc12471c577de575d2072ba1a3cc03c21ad9
|
|
| MD5 |
2dfe584af1c35742669539220ec53426
|
|
| BLAKE2b-256 |
a2363cd50032e29184027dbc32d5e29677479c65092400a1a5d5e1141604d7c6
|