Strongbox.Key (Strongbox v0.1.0-dev)

Copy Markdown View Source

A key of a vault, with the tag that names it in each value it encrypts.

A vault's Strongbox.keys/0 and Strongbox.index_keys/0 may return maps or these structs; Strongbox turns maps into structs and checks them. Inspecting a key never shows its bytes, so a key in a log or an error report gives away only its tag.

Fields

  • :tag - a binary of 1 to 127 bytes, written in front of each value the key encrypts, so the right key is found to decrypt it.
  • :key - the key itself, as a binary.
  • :cipher - for encryption keys, an AEAD cipher of :crypto: :aes_256_gcm (the default), :aes_128_gcm, :aes_256_ccm or :chacha20_poly1305.
  • :format - how values under this key are written and read: :strongbox (the default), :ecto (as Ecto.Encrypted), or, to read values Cloak wrote, :cloak (Cloak's AES.GCM) or :cloak_ctr (Cloak's AES.CTR). See the format guide.
  • :iv_length - for :cloak keys only, the length of Cloak's IVs: 16 unless the Cloak vault was given another :iv_length.
  • :algorithm - for index keys, the hash of the HMAC: :sha256 (the default), :sha384, :sha512, :sha3_256 and so on.

Making a key

$ mix strongbox.gen.key

prints a new random key in Base64. Keep it in an environment variable and read it in config/runtime.exs with decode!/1.

Summary

Functions

Decodes a key kept in Base64, as mix strongbox.gen.key prints it.

Returns bytes random bytes, 32 by default: a new key.

Types

format()

@type format() :: :strongbox | :ecto | :cloak | :cloak_ctr

t()

@type t() :: %Strongbox.Key{
  algorithm: atom(),
  cipher: atom(),
  format: format(),
  iv_length: pos_integer(),
  key: binary(),
  tag: binary()
}

Functions

decode!(base64)

@spec decode!(binary()) :: binary()

Decodes a key kept in Base64, as mix strongbox.gen.key prints it.

Raises ArgumentError without the value if it isn't Base64.

generate(bytes \\ 32)

@spec generate(pos_integer()) :: binary()

Returns bytes random bytes, 32 by default: a new key.