GPG (gpgmex v0.0.3)

Native GnuPG bindings

Warning

This is still a work in progress and the API is likely to change. It is not considered producion quality yet.

Warning

This has only been tested on Linux - It likely won't work for Mac OSX or Windows yet.

Getting Started

You'll need:

Debian based (ubuntu, pop-os, etc)

Installing gpg and gpgme

$ sudo apt install gpg libgpgme-dev

Configuration

Add this to config.exs in your app

config :gpgmex,
  include_dir: ["/usr/include/x86_64-linux-gnu", "/usr/include"],
  lib_dir: ["/usr/lib/x86_64-linux-gnu/libgpgme.so"]

Arch based (Arch, Manjaro, etc)

Installing gpg and gpgme

$ sudo pacman -Syu gpg gpgme

Configuration

Add this to config.exs in your app

config :gpgmex,
  include_dir: ["/usr/include"],
  lib_dir: ["/usr/lib/libgpgme.so"]

Add to your Dependencies

Add gpgmex to your dependencies

defp deps do
  [
    {:gpgmex, "~> 0.0.1"}
  ]
end

Link to this section Summary

Functions

Decrypt the given data.

Delete an existing GPG key

Encrypt data for the requested email recipient

Generate a GPG key using the provided email address.

Get information about the currently installed GPG library

Get the currently installed GPG library version

Get the public key for an email if the public key is on your system

Import a public key

Link to this section Functions

Specs

decrypt(binary()) :: {:ok, binary()} | {:error, binary()}

Decrypt the given data.

This only works if you have the private key available on your system that matches the public key that encrypted it

Examples

iex> GPG.decrypt("-----BEGIN PGP MESSAGE-----\n\nww8K2o8JL1ejKjJSOte0RmhLl6V7M6KW7p9D4Y1zHobTxVnGlmW64wxuWJx03Xs5\nqymK+m7aUrAO0HL3vri3R2z1SisrUAeAtI/4v3GUWA00g4Q0rPzibDe3m53VkY7/\nlyAzJSXL29LL93IJezx53GRK9+RYSBULYWLI3NPX10zidwKbnz+8jo41TIOx0SNh\nt6aAyErC4pnepy7xq7IdWzSe/7v+lrcYpyGT35jyeR+e4N7N7SJV/+WQ+RxBQ/TS\nPwHkMaec6aIgfLTt/lCryJFPEv02C5v0JQg8jJ7SjSH2FOk1y4HPIOJC/qatlLZq\ntDiu13SA0+UBilW1j4AhXA==\n=CXnG\n-----END PGP MESSAGE-----\n")
{:ok, "data"}
Link to this function

delete_key(email)

Specs

delete_key(binary()) :: number() | :error

Delete an existing GPG key

Link to this function

encrypt(email, data)

Specs

encrypt(String.t(), binary()) :: {:ok, binary()} | {:error, atom()}

Encrypt data for the requested email recipient

This works for any public key you have on your system. If you don't have the key on your system {:error, :keynoexist} is returned

Examples

iex> GPG.encrypt("matt@silbernagel.dev", "encrypt this text")
{:ok, "-----BEGIN PGP MESSAGE-----\n\nhQIMA1M1Dqrc4va7AQ/"}
Link to this function

generate_key(email)

Specs

generate_key(String.t()) :: :ok | :error

Generate a GPG key using the provided email address.

This generates a new GPG using rsa3072 encryption. It will use the system prompt to ask for a password.

Examples

iex> GPG.generate_key("my_new@email.com")
:ok
Link to this function

get_engine_info()

Specs

get_engine_info() :: map() | :error

Get information about the currently installed GPG library

Examples

iex> GPG.get_engine_info()
%{filename: "/usr/bin/gpg"}
Link to this function

get_engine_version()

Specs

get_engine_version() :: String.t() | :error

Get the currently installed GPG library version

Examples

iex> GPG.get_engine_version()
"1.17.1"
Link to this function

get_public_key(email)

Specs

get_public_key(binary()) :: binary() | :error

Get the public key for an email if the public key is on your system

Examples

iex> GPG.get_public_key("matt@silbernagel.dev")
"4rZSsLVhrs1JCPtRWmUl1F2q2S5+MqBjTCYkS2Rk\nphuo6u4XQ"
Link to this function

import_key(data)

Specs

import_key(binary()) :: :ok | {:error, binary()}

Import a public key