基于ed25519的nats系统公钥签名系统。
nkeys的Python项目详细描述
Python3的NKEYS
一个基于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”是用户密钥对的种子,“s a”是帐户密钥对的种子。
安装
pip install nkeys
基本API用法
importnkeysimportos# Create an NKEYS KeyPair from a seed file.user=Nonewithopen("user.nkey",'rb',buffering=0)asf:# 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 signaturetry:user.verify(data,sig)exceptnkeys.ErrInvalidSignaturease: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源文件是在许可文件中的Apache2.0版本许可下分发的。