📅  最后修改于: 2023-12-03 15:18:43.248000             🧑  作者: Mango
PSS签名是一种为加密密码学准备的签名扩展方案。 它是实现基于RFC 5652的PSS(Probabilistic Signature Scheme,一种签名方案)的Python库。
PSS签名Python的最新版本可以从Python Package Index(PyPI)上通过pip
命令安装:
pip install pss-signature
from pss_sign import pss_sign
private_key = b'01234567890123456789012345678901' # 128-bit private key
message = b'This is my message.' # The message to be signed
pss_signed_message = pss_sign(private_key, message)
print(pss_signed_message.hex()) # 42c030f37385398a14f47280ebe582a141d579aee02d105cf34c46dd0f7dc106d0efdf15f6c37a8ba3f3c575ea0749919a603422f2678a1b3a91d6eeddc32979
from pss_sign import pss_verify
public_key = b'01234567890123456789012345678901' # 128-bit public key
message = b'This is my message.' # The signed message
signature = bytes.fromhex('42c030f37385398a14f47280ebe582a141d579aee02d105cf34c46dd0f7dc106d0efdf15f6c37a8ba3f3c575ea0749919a603422f2678a1b3a91d6eeddc32979') # The signature for the signed message
pss_signature_valid = pss_verify(public_key, message, signature)
print(pss_signature_valid) # True