GPG (gpgmex v0.0.1)
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:
- a working version of gpg installed
- gpgme c library
- configuration added to
config.exs
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 :zigler,
include: ["/usr/include/x86_64-linux-gnu", "/usr/include"],
libs: ["/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 :zigler,
include: ["/usr/include"],
libs: ["/usr/lib/libgpgme.so"]
Finally
Add gpgmex to your dependencies
defp deps do
[
{:gpgmex, github: "silbermm/gpgmex"}
]
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
Link to this section Functions
decrypt(data)
Specs
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"}
delete_key(email)
Specs
Delete an existing GPG key
encrypt(email, data)
Specs
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/"}
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
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"}
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"
get_public_key(email)
Specs
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"