Skip to main content

Windows BCrypt 加密安全随机数C扩展,与secrets接口完全一致

Project description

secrets-plus

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 secrets-plus

快速使用

import secplus

# 生成各类安全令牌
print(secplus.token_urlsafe())
print(secplus.token_hex(16))
print(secplus.token_bytes(32))

# 随机数工具
print(secplus.randbelow(1000))
print(secplus.randbits(12))

# 序列操作
lst = [1,2,3,4,5]
print(secplus.choice(lst))
secplus.shuffle(lst)
print(lst)

注意事项

  1. 基于栈分配实现,不支持超大长度随机数生成(建议单次长度不超过1024),避免栈溢出
  2. 长期后台运行存在轻微BCrypt句柄残留,短期脚本使用无任何影响

Project details


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.3.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

secrets_plus-0.3.0-cp313-cp313-win_amd64.whl (9.5 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file secrets_plus-0.3.0.tar.gz.

File metadata

  • Download URL: secrets_plus-0.3.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for secrets_plus-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2c1fd8b4af0a287874fe737df451ca617d184470355caf98e2e5d83144103c09
MD5 4a828a09a0c9de8dc7ddb3b06cb1af3d
BLAKE2b-256 76ff210dc57c2f0d2fdcb73acf695f631a5c5459617ee49dc16949b66e4c7ffa

See more details on using hashes here.

File details

Details for the file secrets_plus-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for secrets_plus-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 09323fb10307b35d8828e0cba10b4edcc666e7a13cd5252a054ef7afe07daa6c
MD5 fda9cca2c8e933ec9aec80b89d5403f3
BLAKE2b-256 7c5298758e5dcc8ca735a660cd16f39f881c328ca8f50181b3b3eade25541d3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page