clj-pgp.generate

This namespace provides functionality to generate PGP keypairs and keyrings using a convenient macro syntax.

The two primary supported key types are RSA keys (via rsa-keypair-generator) and Elliptic Curve keys (via ec-keypair-generator). A set of the supported named curves can be found in elliptic-curve-names.

To generate PGP keyrings with designater master keys and subkeys with specific roles and restrictions, use the generate-keys macro. This returns a map with :public and :secret entries containing the respective keyrings.

add-subkey!

(add-subkey! generator subkey sig-gen)

Adds a subkey and signature packet to a keyring genrator.

ec-keypair-generator

(ec-keypair-generator curve & opts)

Constructs a new generator for keypairs on the named elliptic curve.

Opts may include:

  • :random a custom random number generator

elliptic-curve-names

Set of supported elliptic curves.

generate-keypair

(generate-keypair generator algorithm)

Builds a new PGP keypair from a generator.

generate-keyrings

(generate-keyrings keyring-gen)

Generates both the public and secret keyrings from the given generator.

generate-keys

macro

(generate-keys user-id passphrase & key-specs)

Macro to generate keys with a mini-language to specify preferences and subkeys.

An example invocation that creates a master key with signing and encryption subkeys:

(pgp-gen/generate-keys
  "test user" "test passphrase"
  (master-key
    (keypair rsa :rsa-general)
    (prefer-symmetric :aes-256 :aes-128)
    (prefer-hash :sha512 :sha256 :sha1)
    (prefer-compression :zlib :bzip2))
  (signing-key
    (keypair rsa :rsa-general)
    (expires 36000))
  (encryption-key
    (keypair rsa :rsa-general)))

keyring-generator

(keyring-generator user-id passphrase master-key master-sig-gen)

Constructs a new generator for a keyring for a user-id, encrypted with the given passphrase. The provided keypair will become the master key with any options specified in the signature subpacket.

prefer-compression-algorithms!

(prefer-compression-algorithms! generator__8050__auto__ & algorithms__8051__auto__)

Sets the list of preferred algorithms on a signature generator for use when sending messages to the key.

prefer-hash-algorithms!

(prefer-hash-algorithms! generator__8050__auto__ & algorithms__8051__auto__)

Sets the list of preferred algorithms on a signature generator for use when sending messages to the key.

prefer-symmetric-algorithms!

(prefer-symmetric-algorithms! generator__8050__auto__ & algorithms__8051__auto__)

Sets the list of preferred algorithms on a signature generator for use when sending messages to the key.

rsa-keypair-generator

(rsa-keypair-generator strength & opts)

Constructs a new generator for RSA keypairs with the given bit strength. Other parameters may be customized with keyword options.

Opts may include:

  • :random a custom random number generator
  • :exponent RSA algorithm public exponent
  • :certainty threshold for probabilistic prime generation

set-key-expiration!

(set-key-expiration! generator lifetime)

Sets a key expiration time on a signature generator. The lifetime is expressed as a number of seconds since the key creation time.

signature-generator

(signature-generator mode)

Constructs a signature subpacket generator with a preset mode. This can be one of :master, :signing, or :encryption.

signature-subpacket-generator

(signature-subpacket-generator & flags)

Constructs a new generator for key signature subpackets. The given flags will be applied to the key.