跳转到主要内容

基于Ed25519的NATS生态系统公钥签名系统。

项目描述

NKEYS for Python3

License Apache 2 Build Status pypi Versions

基于Ed25519的NATS生态系统公钥签名系统。

关于

NATS生态系统将迁移到Ed25519密钥,用于账户、用户、服务器和集群等实体的身份、认证和授权。

Ed25519速度快且对侧信道攻击具有抵抗力。生成种子密钥就是所有需要存储和保管的,因为种子可以生成公钥和私钥。

NATS系统将利用Ed25519密钥,这意味着NATS系统永远不会存储或甚至访问任何私钥。认证将使用随机挑战响应机制。

处理32字节和64字节的原始密钥可能具有挑战性。NKEYS旨在以更友好的方式生成密钥,并参考了加密货币领域的工作,特别是Stellar。比特币和其他加密货币使用了Base58(或Base58Check)的形式来编码原始密钥。Stellar使用了传统的Base32,并带有CRC16和一个版本或前缀字节。NKEYS采用了类似的格式,其中公钥和私钥的前缀为1字节,种子为2字节。这些前缀的Base32编码将产生易于人类阅读的前缀,例如 'N' 表示服务器,'C' 表示集群,'O' 表示操作员,'A' 表示账户,以及 'U' 表示用户。'P' 用于私钥。对于种子,第一个编码的前缀是 'S',第二个字符将表示公钥的类型,例如 "SU" 是用户密钥对的种子,"SA" 是账户密钥对的种子。

安装

pip install nkeys

基本API使用

import nkeys
import os

# Create an NKEYS KeyPair from a seed file.
user = None
with open("user.nkey", 'rb', buffering=0) as f:

  # We compute the size of the file to allocate the required
  # bytearray size in order to have control over the memory
  # and be able to wipe it once the keys are not needed anymore.
  seed = bytearray(os.fstat(f.fileno()).st_size)
  f.readinto(seed)
  user = nkeys.from_seed(seed)

# Sign some data with the KeyPair user.
data = b'arGTKH8q7XDmgy0'
sig = user.sign(data)

# Verify the signature
try: 
  user.verify(data, sig)
except nkeys.ErrInvalidSignature as e:
  print("Error:", e)

# Access the seed, the only thing that needs to be stored and kept safe.
print(user.seed)

# Remove any secrets that were in use by the KeyPair.
user.wipe()

许可证

除非另有说明,否则NATS源文件根据LICENSE文件中的Apache Version 2.0许可进行分发。

项目详情


下载文件

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

源分发

nkeys-0.2.1.tar.gz (10.7 kB 查看散列值)

上传时间

由以下机构支持

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