GPG (gpgmex v0.0.9)

Native GnuPG bindings

warning

Warning

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

warning-1

Warning

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

getting-started

Getting Started

You'll need:

debian-based-ubuntu-pop-os-etc

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,
  gpg_home: "~/.gnupg",    # where your gpg home path is
  gpg_path: "/usr/bin/gpg" # where your gpg binary lives

arch-based-arch-manjaro-etc

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,
  gpg_home: "~/.gnupg",    # where your gpg home path is
  gpg_path: "/usr/bin/gpg" # where your gpg binary lives

add-to-your-dependencies

Add to your Dependencies

Add gpgmex to your dependencies

defp deps do
  [
    {:gpgmex, "~> 0.0.7"}
  ]
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 fingerprint of the public key for an email if the public key is on your system

Import a public key

Gets data about a public key

Link to this section Functions

@spec 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

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)

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

Delete an existing GPG key

Link to this function

encrypt(email, data)

@spec 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

Examples

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

generate_key(email)

@spec 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

Examples

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

get_engine_info()

@spec get_engine_info() :: map() | :error

Get information about the currently installed GPG library

examples

Examples

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

get_engine_version()

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

Get the currently installed GPG library version

examples

Examples

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

get_public_key(email)

@spec get_public_key(binary()) :: {:ok, binary()} | :error

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

examples

Examples

iex> GPG.get_public_key("matt@silbernagel.dev")
{:ok, "80C8F7AE64E589449FB0A03974DB6708422DD33B"}
Link to this function

import_key(data)

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

Import a public key

Link to this function

key_info(public_key)

@spec key_info(binary()) :: map() | {:error, binary()}

Gets data about a public key