Home

Awesome

RSA Ex

Library for working with RSA keys using Elixir and OpenSSL ports.

Installation

If available in Hex, the package can be installed as:

def deps do
  [{:rsa_ex, "~> 0.4"}]
end
def application do
  [applications: [:rsa_ex]]
end

Usage

iex> {:ok, priv} = RsaEx.generate_private_key
iex> {:ok, priv} = RsaEx.generate_private_key
iex> {:ok, pub} = RsaEx.generate_public_key(priv)
iex> {:ok, priv} = RsaEx.generate_private_key("4096")
iex> {:ok, pub} = RsaEx.generate_public_key(priv)
iex> {:ok, {priv, pub}} = RsaEx.generate_keypair
iex> {:ok, {priv, pub}} = RsaEx.generate_keypair("4096")
iex> {:ok, rsa_private_key} = RsaEx.generate_private_key
iex> {:ok, signature} = RsaEx.sign("message", rsa_private_key)
iex> {:ok, rsa_private_key} = RsaEx.generate_private_key
iex> {:ok, signature} = RsaEx.sign("message", rsa_private_key, :sha512)
iex> {:ok, valid} = RsaEx.verify(message, signature, rsa_public_key)
iex> {:ok, valid} = RsaEx.verify(message, signature, rsa_public_key, :sha512)
iex> clear_text = "Important message"
"Important message"
iex> {:ok, cipher_text} = RsaEx.encrypt(clear_text, {:public_key, rsa_public_key})
{:ok, "Lmbv...HQ=="}
iex> clear_text = "Important message"
"Important message"
iex> {:ok, cipher_text} = RsaEx.encrypt(clear_text, {:private_key, rsa_private_key})
{:ok, "Lmbv...HQ=="}
iex> {:ok, decrypted_clear_text} = RsaEx.decrypt(cipher_text, {:private_key, rsa_private_key})
{:ok, "Important message"}
iex> {:ok, decrypted_clear_text} = RsaEx.decrypt(cipher_text, {:public_key, rsa_public_key})
{:ok, "Important message"}