2.2. Digital Signatures
Digital signatures are implemented using the RSA cryptosystem. These types and functions are designed for signing purposes only (that is, not for encrypting data), as this signature cryptosystem is non-reversible. If you need to encrypt data, use Asymmetric Encryption.
2.2.1. Types
- class SignatureVerifyKey
The RSA public key for signature verification.
- class SignatureSignKey
The RSA private key for signature creation.
2.2.2. Functions
- crypto.SignatureKeyGen() Tuple[SignatureVerifyKey, SignatureSignKey]
Generates a public-key pair for asymmetric encryption purposes.
- Returns:
A tuple corresponding to a
SignatureVerifyKeyandSignatureSignKeypair- Return type:
Tuple[SignatureVerifyKey, SignatureSignKey]
Example usage:
# Returns a tuple, so assign return values to two variables: public_key, private_key = crypto.SignatureKeyGen()
- crypto.SignatureSign(key: SignatureSignKey, message: bytes) bytes
Returns a signature on
messageusing the private keykey.messagedoes not need to be hashed in advance of passing it to this function.- Parameters:
key (
SignatureSignKey) – The private keymessage (bytes) – The bytes to sign
- Returns:
The resulting signature
- Return type:
bytes
- crypto.SignatureVerify(key: SignatureVerifyKey, message: bytes, signature: bytes) bool
Uses the public key
keyto verify thatsignatureis a valid signature formessage.- Parameters:
key (
SignatureVerifyKey) – The public key to sign withmessage (bytes) – The message to verify
signature (bytes) – The signature to verify
- Returns:
Trueif verification succeeds; otherwise,False- Return type:
bool
2.2.3. Class Methods
Note
You probably don’t have to worry about the methods below if you’re just thinking about the design, but you’ll probably need to use them once you start implementing your client application.
These class methods are for the purposes of serialization (see Serialization API). Also, see Key Serialization Example for example usage.
- classmethod crypto.SignatureVerifyKey.from_bytes(b: bytes) SignatureVerifyKey
Converts a serialized
bytesrepresentation of aSignatureVerifyKeyto an actual Python instance ofSignatureVerifyKey.- Returns:
The deserialized
SignatureVerifyKeyinstance- Return type:
- Raises:
ValueError – if
bwas not a valid encoding of aSignatureVerifyKeyinstance
- classmethod crypto.SignatureSignKey.from_bytes(b: bytes) SignatureSignKey
Converts a serialized
bytesrepresentation of aSignatureSignKeyto an actual Python instance ofSignatureSignKey.- Returns:
The deserialized
SignatureSignKeyinstance- Return type:
- Raises:
ValueError – if
bwas not a valid encoding of aSignatureSignKeyinstance