View Source SecretVault.Cipher behaviour (SecretVault v1.2.2)

Provides an interface to implement encryption methods.

See SecretVault.Cipher.ErlangCrypto implementation for more details.

Summary

Types

Binary blob that contains encrypted data.

A key for symetric encryption algorithm as a binary.

Binary blob that contains decrypted data.

Callbacks

Decrypt the cypher_text with the key used to get it.

Encrypt the plain_text with the key.

Functions

Serialize encryption metadata end a ciphertext into a single binary.

Deserialize pack/3'ed data.

Types

@type cypher_text() :: binary()

Binary blob that contains encrypted data.

@type key() :: binary()

A key for symetric encryption algorithm as a binary.

@type plain_text() :: binary()

Binary blob that contains decrypted data.

Callbacks

Link to this callback

decrypt(key, cypher_text, opts)

View Source
@callback decrypt(key(), cypher_text(), opts) ::
  {:ok, plain_text()} | {:error, :invalid_encryption_key}
when opts: Keyword.t()

Decrypt the cypher_text with the key used to get it.

If key is invalid, :invalid_key error is returned. If inappropriate text is passed as cypher_text, Cipher.Error is raised.

Link to this callback

encrypt(key, plain_text, opts)

View Source
@callback encrypt(key(), plain_text(), opts) :: cypher_text() when opts: Keyword.t()

Encrypt the plain_text with the key.

Functions

Link to this function

pack(cipher, algorithm, properties)

View Source
@spec pack(cipher, algorithm, [property]) :: binary()
when cipher: String.t(), algorithm: String.t(), property: binary()

Serialize encryption metadata end a ciphertext into a single binary.

This is a helper function to prepare the data to be written on the disk.

Example

iex> cipher = "MyNewCipher"
...> algorithm = "default"
...> ciphertext = "testtest"
...> pack(cipher, algorithm, [ciphertext])
"MyNewCipher;default;7465737474657374"
@spec unpack!(cipher, binary()) :: [property]
when cipher: String.t(), property: binary()

Deserialize pack/3'ed data.

Example

iex> cipher = "MyNewCipher"
iex> serialized = "MyNewCipher;default;7465737474657374"
iex> unpack!(cipher, serialized)
["default", "testtest"]