View Source simple-rijndael for Elixir

A binding to the PurePeace's simple-rijndael Rust crate for Elixir.

PayPal GitHub Sponsor Hex.pm HexDocs.pm

Motivation

AES has removed the block size of 256 bits from the standard and if a old system is using it AES willn't work (my case) and there's no Rijndael implementations in Erlang or Elixir.

Installation

Warning: You will need the Rust compiler to compile this package.

This package has been published in Hex.pm and you can use it with:

def deps do
  [
    {:simple_rijndael, "~> 0.1.0"}
  ]
end

Usage

key = :crypto.strong_rand_bytes(32)
iv = :crypto.strong_rand_bytes(32)

# Padding options:
#   :pkcs7
#   :zero
{:ok, cipher} = SimpleRijndael.init_cbc_mode(key, 32, :pkcs7)

data = "Hello, World!"

{:ok, encrypted} = SimpleRijndael.encrypt(cipher, iv, data)

{:ok, decrypted} = SimpleRijndael.decrypt(cipher, iv, encrypted)

# If an error occour, will be one of the following returns:
#   {:error, :invalid_data_size}
#   {:error, :invalid_key_size}
#   {:error, :invalid_block_size}
#
# Or an exception of ErlangError with reason == nil and original == :nif_panicked

Credits

Simple Rijndael for Elixir is a project by Nashira Deer, licensed under MIT License.