公钥安全传输层
pkstl的Python项目详细描述
Py PKSTL公司
Rust PKSTL的Python 3绑定。PKSTL是网络连接的安全层(公钥加密和Diffie-Hellman secret generation)。在
安装
sudo pip3 install pkstl
生成和安装
^{pr2}$示例
运行一个示例(客户机-服务器echo):
python3 py/example_echo.py server
python3 py/example_echo.py client
# and type some text into the client!
最小示例代码:(Bob知道Alice的公钥并与她联系)
import pkstl
# Generate keypairs
alice_seed = pkstl.Seed32.random() # Alice's permanent private key
alice_pubkey = pkstl.Ed25519KeyPair.from_seed_unchecked(alice_seed.bytes).pubkey
bob_seed = pkstl.Seed32.random() # Bob's ephemeral private key
alice_msl = pkstl.SecureLayer.create(pkstl.SecureLayerConfig.default(), alice_seed)
bob_msl = pkstl.SecureLayer.create(pkstl.SecureLayerConfig.default(), bob_seed, alice_pubkey)
# Establish connection
msg = bob_msl.write_connect_msg_bin(b"Hello Alice!")
alice_msl.read_bin(msg)
msg = alice_msl.write_connect_msg_bin(b"Hello Bob!")
bob_msl.read_bin(msg)
msg = alice_msl.write_ack_msg_bin(b"Nice to meet you Bob!")
bob_msl.read_bin(msg)
msg = bob_msl.write_ack_msg_bin(b"Nice to meet you Alice!")
alice_msl.read_bin(msg)
# Send messages
msg = alice_msl.write_bin(b"Is this channel encrypted?")
print(bob_msl.read_bin(msg)[0].data[0])
msg = bob_msl.write_bin(b"Yes it is.")
print(alice_msl.read_bin(msg)[0].data[0])
- 项目
标签: