View Source SecretVault.Cipher behaviour (SecretVault v1.0.0)
Provides an interface to implement encryption methods.
See SecretVault.Cipher.ErlangCrypto
implementation for more
details.
Link to this section Summary
Types
Binary blob that contains encrypted data.
A key for symetric encryption algorithm as a binary.
Binary blob that contains decrypted data.
Link to this section Types
Link to this section 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
.
Link to this section 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
Example
iex> cipher = "MyNewCipher"
...> algorithm = "default"
...> ciphertext = "testtest"
...> pack(cipher, algorithm, [ciphertext])
"MyNewCipher;default;7465737474657374"
Deserialize pack/3
'ed data.
example
Example
iex> cipher = "MyNewCipher"
iex> serialized = "MyNewCipher;default;7465737474657374"
iex> unpack!(cipher, serialized)
["default", "testtest"]