fields v2.1.0 Fields.AES
Encrypt values with AES in Galois/Counter Mode (GCM)
https://en.wikipedia.org/wiki/Galois/Counter_Mode
using a random Initialisation Vector for each encryption,
this makes "bruteforce" decryption much more difficult.
See encrypt/1
and decrypt/1
for more details.
Link to this section Summary
Functions
Decrypt a binary using GCM.
Encrypt Using AES Galois/Counter Mode (GCM)
https://en.wikipedia.org/wiki/Galois/Counter_Mode
Uses a random IV for each call, and prepends the IV and Tag to the
ciphertext. This means that encrypt/1
will never return the same ciphertext
for the same value. This makes "cracking" (bruteforce decryption) much harder!
Link to this section Functions
Decrypt a binary using GCM.
Parameters
ciphertext
: a binary to decrypt, assuming that the first 16 bytes of the binary are the IV to use for decryption.key_id
: the index of the AES encryption key used to encrypt the ciphertext
Example
iex> Fields.AES.encrypt("test") |> Fields.AES.decrypt()
"test"
Encrypt Using AES Galois/Counter Mode (GCM)
https://en.wikipedia.org/wiki/Galois/Counter_Mode
Uses a random IV for each call, and prepends the IV and Tag to the
ciphertext. This means that encrypt/1
will never return the same ciphertext
for the same value. This makes "cracking" (bruteforce decryption) much harder!
Parameters
plaintext
: Accepts any data type as all values are converted to a String usingto_string
before encryption.key_id
: the index of the AES encryption key used to encrypt the ciphertext
Examples
iex> Fields.AES.encrypt("tea") != Fields.AES.encrypt("tea")
true
iex> ciphertext = Fields.AES.encrypt(123)
iex> is_binary(ciphertext)
true