Module bastionlab.keys
Classes
Identity()
-
Static methods
create(name: Optional[str] = 'bastionlab-identity', password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey
-
Generate a new signing key with the given name and password.
Args: name: The name to use for the signing key. If not provided, the default name "bastionlab-identity" will be used. password: The password to use to encrypt the signing key. If not provided, the key will not be encrypted.
Returns: The generated signing key.
load(name: str) ‑> bastionlab.keys.SigningKey
-
Load a signing key with the given name.
Args: name: The name of the signing key to load.
Returns: The signing key with the given name.
PublicKey()
-
A class for representing a public key. This class provides methods for encrypting and verifying messages, as well as converting the key to and from various formats (e.g. bytes, PEM).
Initialize a
PublicKey
instance with a given public key type.Args: key: An EC public key type.
Static methods
from_bytes_content(content: bytes) ‑> bastionlab.keys.PublicKey
-
Load a
PublicKey
instance from a DER-encoded byte string.Args: content: The DER-encoded byte string to load the key from.
Returns: The
PublicKey
instance loaded from the given byte string. from_pem(path: str) ‑> bastionlab.keys.PublicKey
-
Load a
PublicKey
instance from a PEM-encoded file.Args: path: The path to the file to load the key from.
Returns: The
PublicKey
instance loaded from the given file. from_pem_content(content: bytes) ‑> bastionlab.keys.PublicKey
-
Load a
PublicKey
instance from a PEM-encoded byte string.Args: content: The PEM-encoded byte string to load the key from.
Returns: The
PublicKey
instance loaded from the given byte string.
Instance variables
hash: bytes
-
Get the hash of this
PublicKey
instance.Returns: The hash of this
PublicKey
instance. pem: str
-
Get the PEM encoding of this
PublicKey
instance.Returns: The PEM encoding of this
PublicKey
instance.
Methods
__eq__(self, o: object) ‑> bool
-
Compare this
PublicKey
instance with another object for equality.Args: o: The object to compare with.
Returns: True if the objects are equal, False otherwise.
as_bytes(self) ‑> bytes
-
Get the DER encoding of this
PublicKey
instance.Returns: The DER encoding of this
PublicKey
instance. save_pem(self, path: str) ‑> bastionlab.keys.PublicKey
-
Save this
PublicKey
instance to a PEM-encoded file.Args: path: The path to save the key to.
Returns: This
PublicKey
instance. verify(self, signature: bytes, data: bytes) ‑> None
-
Verify that the given signature is valid for the given data.
Args: signature: A signature to verify. data: The data that the signature should be for.
Raises: ValueError: if the signature is not valid for the given data.
SigningKey()
-
A class for representing a signing key. This class is used for creating digital signatures and verifying them. It contains both the private key (used for signing) and the corresponding public key (used for verification).
Static methods
from_pem(path: str, password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey
-
Load a
PublicKey
instance from a PEM-encoded file.Args: path: The path to the file to load the key from.
Returns: The
PublicKey
instance loaded from the given file. from_pem_content(content: bytes, password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey
-
Load a
SigningKey
instance from a PEM-encoded byte string.Args: content: The PEM-encoded byte string to load the key from. password: The password to use to decrypt the key, if it is encrypted.
Returns: The
SigningKey
instance loaded from the given byte string. generate() ‑> bastionlab.keys.SigningKey
-
Generate a new
SigningKey
instance.Returns: A new
SigningKey
instance. keygen(path: str, password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey
-
Generate a new signing key and save it to the given file.
Args: path: The path to the file to save the signing key to. password: The password to use to encrypt the signing key. If not provided, the key will not be encrypted.
Returns: The generated signing key.
Instance variables
pubkey: bastionlab.keys.PublicKey
-
Get the public key associated with this
SigningKey
instance.Returns: The public key associated with this
SigningKey
instance.
Methods
__eq__(self, o: object) ‑> bool
- Return self==value.
save_pem(self, path: str, password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey
-
Save this
PublicKey
instance to a PEM-encoded file.Args: path: The path to save the key to.
Returns: This
PublicKey
instance. sign(self, data: bytes) ‑> bytes
-
Sign the given data with this
SigningKey
instance's private key.Args: data: The data to sign.
Returns: The signature for the given data.