---
title: "Gpg decryption without pin entry pop up using GPGME"
description: "Gpg decryption without pin entry pop up using GPGME"
canonical_url: "https://www.bigbinary.com/blog/gpg-decryption-without-pin-entry-pop-up-using-gpgme"
markdown_url: "https://www.bigbinary.com/blog/gpg-decryption-without-pin-entry-pop-up-using-gpgme.md"
---

# Gpg decryption without pin entry pop up using GPGME

Gpg decryption without pin entry pop up using GPGME

- Author: Sushant Mittal
- Published: March 27, 2018
- Categories: Rails

In one of our projects, we implemented GPG decryption.

What is GPG ?

> GPG is a complete and free implementation of the OpenPGP standard as defined
> by [RFC4880](https://www.ietf.org/rfc/rfc4880.txt) (also known as PGP).

We used [GPGME](https://github.com/ueno/ruby-gpgme) gem for this purpose. It
provides three levels of API. In our case, we used
[Crypto](https://github.com/ueno/ruby-gpgme#crypto) which has the high level
convenience methods to encrypt, decrypt, sign and verify signatures.

We needed to import private key for decrypting a file that was encrypted using
paired public key. First let's import the required private key.

```ruby
GPGME::Key.import File.open('certs/pgp.key')
```

Let's decrypt the file.

```ruby
crypto = GPGME::Crypto.new
options = { output: File.open('file.csv', 'wb') }

crypto.decrypt File.open('file.csv.gpg'), options
```

Above code has one problem. It will open a pop up for password input that has
been used when public and private keys have been generated.

To support password input without pop up, we updated the code as below.

```ruby
crypto = GPGME::Crypto.new
options = {
            output: File.open('file.csv', 'wb'),
            pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK,
            password: 'welcome'
          }

crypto.decrypt File.open('file.csv.gpg'), options
```

Here, `pinentry_mode` option allows password input without pop up.

We did not use latest version of GPG since it does not support `pinentry_mode`
option. Instead, We used `2.1.20` version which has support for this option.
[Here](https://gist.github.com/mattrude/3883a3801613b048d45b) is the build
instruction for that.

## Links

- [Human page](https://www.bigbinary.com/blog/gpg-decryption-without-pin-entry-pop-up-using-gpgme)
