exth_crypto v0.1.1 ExthCrypto.Cipher
Module for symmetric encryption.
Link to this section Summary
Functions
Decrypts the given ciphertext from the given block cipher
Encrypts the given plaintext for the given block cipher
Generate a random initialization vector for the given type of cipher
Link to this section Types
Link to this section Functions
Link to this function
decrypt(ciphertext, symmetric_key, init_vector, cipher)
decrypt(ciphertext, ExthCrypto.symmetric_key, init_vector, cipher) :: plaintext
Decrypts the given ciphertext from the given block cipher.
Examples
iex> "4f0150273733727f994754fee054df7e18ec169892db5ba973cf8580b898651b"
...> |> ExthCrypto.Math.hex_to_bin
...> |> ExthCrypto.Cipher.decrypt(ExthCrypto.Test.symmetric_key, ExthCrypto.Test.init_vector, {ExthCrypto.AES, ExthCrypto.AES.block_size, :cbc})
<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>> <> "execute order 66"
iex> "2a7935444247175ff635309b9274e948"
...> |> ExthCrypto.Math.hex_to_bin
...> |> ExthCrypto.Cipher.decrypt(ExthCrypto.Test.symmetric_key, ExthCrypto.Test.init_vector, {ExthCrypto.AES, ExthCrypto.AES.block_size, :ctr})
"execute order 66"
Link to this function
encrypt(plaintext, symmetric_key, init_vector, cipher)
encrypt(plaintext, ExthCrypto.symmetric_key, init_vector, cipher) :: ciphertext
Encrypts the given plaintext for the given block cipher.
Examples
iex> ExthCrypto.Cipher.encrypt("execute order 66", ExthCrypto.Test.symmetric_key, ExthCrypto.Test.init_vector, {ExthCrypto.AES, ExthCrypto.AES.block_size, :cbc}) |> ExthCrypto.Math.bin_to_hex
"4f0150273733727f994754fee054df7e18ec169892db5ba973cf8580b898651b"
iex> ExthCrypto.Cipher.encrypt("execute order 66", ExthCrypto.Test.symmetric_key, ExthCrypto.Test.init_vector, {ExthCrypto.AES, ExthCrypto.AES.block_size, :ctr}) |> ExthCrypto.Math.bin_to_hex
"2a7935444247175ff635309b9274e948"