GPG (gpgmex v0.1.1)
Native GnuPG bindings
warning
WarningThis is still a work in progress and the API is likely to change. It is not considered producion quality yet.
warning-1
WarningThis has only been tested on Linux - It likely won't work for Mac OSX or Windows yet.
getting-started
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
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.12"}
]
end
Link to this section Summary
Functions
Clearsigning causes the data to be wrapped in an ASCII-armored signature but otherwise does not modify the data.
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
List all known keys on the system.
Verifys the clear signed data.
Link to this section Functions
clear_sign(data)
Clearsigning causes the data to be wrapped in an ASCII-armored signature but otherwise does not modify the data.
This allows recipients of the data to verify that it is indeed from the correct person.
examples
Examples
iex> GPG.clear_sign("data")
{:ok, "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA512\n\ndata\n-----BEGIN PGP SIGNATURE-----\n\niQIzBAEBCgAdFiEEgMj3rmTliUSfsKA5dNtnCEIt0zsFAmQPzq0ACgkQdNtnCEIt\n0zvsmw/+JZWfHhbHgqy9lw11QuagovqV0HQdk9C/wrzbrmeAP8g+AvkDDbo2GTP7\neHOfOaWJDCD6qWvSt//JIs8khQfnQ3faBhPunQt+iPze1N9JSKTbJway3fJKr5dQ\nyFAjFDt/AHFCGUzE37eld/TE+ehsj3H7fTxAe9GdPWM3r3n9MpggzCb5YQYSk7yy\nYdWOWIhbyVt7RTk4hzuNh4wWaprQvuU38saDMMkZbHUxR0oIIoomfgsywLdb0HZA\n8iGvex7uqyWPHCY2NMpdSJ4E0xBNURwarlHE32/sRZrISAMfW/nWY4tTWFHN8Spz\ncBDclyzFkwjihMz/+9Dl4VfTN7UQuFh3/4Z12dl0RS9d1sz45bVcNy5DapArviOj\nmaAzvYyodWQ8qthWZDT+ZAPCIky61gVLkcxqXArTamoxQbxBsLkGrNx2Up8caYBK\nPH6o8XuIXTb640jzpOgPSL63qfn3HgvZr/9nyyhrZv3ASroSOCcLgvBaxl4MZ0pN\nKnKJnklhCKdKcz2as+KPpWGXA7WKY5s/7JQdZDdSA2zYHwirNI0qaZ5UFgkyJWzJ\ncu+v/ZjVgeidPKCD65Yn3UIY2wXWTqDcI5sSWXFTHnVljEeC16yjuzYWXgvYLDrM\n0ypPbndz7WBckg5UKukAWPwQl0P61zBmywx13UZ1/9cww7Gp9Jw=\n=MgoU\n-----END PGP SIGNATURE-----\n"}
decrypt(data)
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"}
delete_key(email)
Delete an existing GPG key
encrypt(email, data)
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/"}
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
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"}
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"
get_public_key(email)
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"}
import_key(data)
Import a public key
key_info(public_key)
Gets data about a public key
list_keys()
@spec list_keys() :: [map()]
List all known keys on the system.
verify_clear(data)
Verifys the clear signed data.
examples
Examples
iex> GPG.verify_clear("-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA512\n\ndata\n-----BEGIN PGP SIGNATURE-----\n\niQIzBAEBCgAdFiEEgMj3rmTliUSfsKA5dNtnCEIt0zsFAmQPzq0ACgkQdNtnCEIt\n0zvsmw/+JZWfHhbHgqy9lw11QuagovqV0HQdk9C/wrzbrmeAP8g+AvkDDbo2GTP7\neHOfOaWJDCD6qWvSt//JIs8khQfnQ3faBhPunQt+iPze1N9JSKTbJway3fJKr5dQ\nyFAjFDt/AHFCGUzE37eld/TE+ehsj3H7fTxAe9GdPWM3r3n9MpggzCb5YQYSk7yy\nYdWOWIhbyVt7RTk4hzuNh4wWaprQvuU38saDMMkZbHUxR0oIIoomfgsywLdb0HZA\n8iGvex7uqyWPHCY2NMpdSJ4E0xBNURwarlHE32/sRZrISAMfW/nWY4tTWFHN8Spz\ncBDclyzFkwjihMz/+9Dl4VfTN7UQuFh3/4Z12dl0RS9d1sz45bVcNy5DapArviOj\nmaAzvYyodWQ8qthWZDT+ZAPCIky61gVLkcxqXArTamoxQbxBsLkGrNx2Up8caYBK\nPH6o8XuIXTb640jzpOgPSL63qfn3HgvZr/9nyyhrZv3ASroSOCcLgvBaxl4MZ0pN\nKnKJnklhCKdKcz2as+KPpWGXA7WKY5s/7JQdZDdSA2zYHwirNI0qaZ5UFgkyJWzJ\ncu+v/ZjVgeidPKCD65Yn3UIY2wXWTqDcI5sSWXFTHnVljEeC16yjuzYWXgvYLDrM\n0ypPbndz7WBckg5UKukAWPwQl0P61zBmywx13UZ1/9cww7Gp9Jw=\n=MgoU\n-----END PGP SIGNATURE-----\n")
{:ok, "data\n"}