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.
Types
Callbacks
@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.
@callback encrypt(key(), plain_text(), opts) :: cypher_text() when opts: Keyword.t()
Encrypt the plain_text
with the key
.
Functions
@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"
Deserialize pack/3
'ed data.
Example
iex> cipher = "MyNewCipher"
iex> serialized = "MyNewCipher;default;7465737474657374"
iex> unpack!(cipher, serialized)
["default", "testtest"]