Acquire.Crypto._keys module

class PrivateKey(private_key=None, auto_generate=True)[source]

Bases: object

This is a holder for an in-memory private key

bytes(passphrase, mangleFunction=None)[source]

Return the raw bytes for this key, encoded by the passed passphrase that has been optionally mangled by mangleFunction

decrypt(message)[source]

Decrypt and return the passed message

encrypt(message)[source]

Encrypt and return the passed message

fingerprint()[source]

Return the fingerprint of this key - this is useful to help work out which key to use to decrypt data

static from_data(data, passphrase, mangleFunction=None)[source]

Return a private key constructed from the passed json-deserialised dictionary

key_size_in_bytes()[source]

Return the number of bytes in this key

pem(passphrase, mangleFunction=None)[source]

Return a PEM string for this key

public_key(filename=None)[source]

Get the public key for this private key. If filename is specified then this is written to the passed file

static random_passphrase()[source]

Randomly generate and return a passphrase that obeys the password rules and could be used to serialise a PrivateKey

static read(filename, passphrase, mangleFunction=None)[source]

Read a private key from ‘filename’ that is encrypted using ‘passphrase’ and return a PrivateKey object holding that key

static read_bytes(data, passphrase, mangleFunction=None)[source]

Read a private key from the passed bytes ‘data’ that is encrypted using ‘passphrase’ and return a PrivateKey object holding that key

sign(message)[source]

Return the signature for the passed message

to_data(passphrase, mangleFunction=None)[source]

Return the json-serialisable data for this key

verify(signature, message)[source]

Verify the passed signature is correct for the passed message

write(filename, passphrase, mangleFunction=None)[source]

Write this key to ‘filename’, encrypted with ‘passphrase’

class PublicKey(public_key=None)[source]

Bases: object

This is a holder for an in-memory public key

bytes()[source]

Return the raw bytes for this key

encrypt(message)[source]

Encrypt and return the passed message. For short messages this will use the private key directly. For longer messages, this will generate a random symmetric key, will encrypt the message using that, and will then encrypt the symmetric key. This returns some bytes

fingerprint()[source]

Return the fingerprint of this key - this is useful to help work out which key to use to decrypt data

static from_data(data)[source]

Construct from the passed json-deserialised dictionary

pem()[source]

Return a PEM string for this key

static read(filename)[source]

Read and return a public key from ‘filename’

static read_bytes(data)[source]

Read and return a public key from ‘data’

to_data()[source]

Return this public key as a json-serialisable dictionary

verify(signature, message)[source]

Verify that the message has been correctly signed

write(filename)[source]

Write this public key to ‘filename’

class SymmetricKey(symmetric_key=None, auto_generate=True)[source]

Bases: object

This is a holder for an in-memory symmetric key (for symmetric encryption)

bytes(passphrase, mangleFunction=None)[source]

Return the raw bytes for this key, encoded by the passed passphrase that has been optionally mangled by mangleFunction

decrypt(message)[source]

Decrypt and return the passed message

encrypt(message)[source]

Encrypt and return the passed message

fingerprint()[source]

Return the fingerprint of this key - this is useful to help work out which key to use to decrypt data

static from_data(data, passphrase, mangleFunction=None)[source]

Return a key constructed from the passed json-deserialised dictionary

static random_passphrase()[source]

Randomly generate and return a passphrase that obeys the password rules and could be used to serialise a SymmetricKey

static read(filename, passphrase, mangleFunction=None)[source]

Read a private key from ‘filename’ that is encrypted using ‘passphrase’ and return a SymmetricKey object holding that key

static read_bytes(data, passphrase, mangleFunction=None)[source]

Read a SymmetricKey from the passed bytes ‘data’ that is encrypted using ‘passphrase’ and return a SymmetricKey object holding that key

to_data(passphrase, mangleFunction=None)[source]

Return the json-serialisable data for this key

write(filename, passphrase, mangleFunction=None)[source]

Write this key to ‘filename’, encrypted with ‘passphrase’

get_private_key(key='default')[source]

Internal function used to return the key associated with ‘key’. This allows a single session to re-use a key, rather than continually generating new keys (which is slow). Make sure you know that you can safely re-use a key. Re-using keys for different function calls is completely ok