unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Transparent encrypt and decrypt token file with gpg2 in Emacs.
@ 2021-06-09 15:12 Hongyi Zhao
  2021-06-09 16:03 ` Jean Louis
  0 siblings, 1 reply; 4+ messages in thread
From: Hongyi Zhao @ 2021-06-09 15:12 UTC (permalink / raw)
  To: help-gnu-emacs

On Ubuntu 20.04, I store the API token in a file with an extension
name gpg. Then I load this file in init-file.

But when I always notice that when the content of the token file is
read by Emacs, the following error will be triggered:

In the *Error* buffer:

Error while decrypting with "/usr/bin/gpg2":

gpg: no valid OpenPGP data found.
gpg: decrypt_message failed: Unknown system error

In the *Message* buffer:

Loading /home/werner/DvdMgr/screen2latex.el.git/auth.el.gpg...
Decrypting /home/werner/DvdMgr/screen2latex.el.git/auth.el.gpg...done
epa-file-insert-file-contents: Opening input file: Can't decrypt, No
data (no armored data); No data (expected a packet but did not find
one); Exit
Mark set [4 times]

Any hints for solving this problem?

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Transparent encrypt and decrypt token file with gpg2 in Emacs.
  2021-06-09 15:12 Transparent encrypt and decrypt token file with gpg2 in Emacs Hongyi Zhao
@ 2021-06-09 16:03 ` Jean Louis
  2021-06-10  2:19   ` Hongyi Zhao
  0 siblings, 1 reply; 4+ messages in thread
From: Jean Louis @ 2021-06-09 16:03 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

* Hongyi Zhao <hongyi.zhao@gmail.com> [2021-06-09 18:28]:
> Loading /home/werner/DvdMgr/screen2latex.el.git/auth.el.gpg...
> Decrypting /home/werner/DvdMgr/screen2latex.el.git/auth.el.gpg...done
> epa-file-insert-file-contents: Opening input file: Can't decrypt, No
> data (no armored data); No data (expected a packet but did not find
> one); Exit
> Mark set [4 times]

Send the file for review.

If it is encrypted, there should be nothing much to worry... ^‿^
-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Transparent encrypt and decrypt token file with gpg2 in Emacs.
  2021-06-09 16:03 ` Jean Louis
@ 2021-06-10  2:19   ` Hongyi Zhao
  2021-06-10  5:08     ` Hongyi Zhao
  0 siblings, 1 reply; 4+ messages in thread
From: Hongyi Zhao @ 2021-06-10  2:19 UTC (permalink / raw)
  To: Hongyi Zhao, help-gnu-emacs

On Thu, Jun 10, 2021 at 12:06 AM Jean Louis <bugs@gnu.support> wrote:
>
> * Hongyi Zhao <hongyi.zhao@gmail.com> [2021-06-09 18:28]:
> > Loading /home/werner/DvdMgr/screen2latex.el.git/auth.el.gpg...
> > Decrypting /home/werner/DvdMgr/screen2latex.el.git/auth.el.gpg...done
> > epa-file-insert-file-contents: Opening input file: Can't decrypt, No
> > data (no armored data); No data (expected a packet but did not find
> > one); Exit
> > Mark set [4 times]
>
> Send the file for review.
>
> If it is encrypted, there should be nothing much to worry... ^‿^

If I first store the plain/unencrypted token info into a file, say,
named as auth.el, and then encrypt it outside of Emacs with gpg(2) as
below, the problem will disappear:

$ gpg2 -o auth.el.gpg -e -r hongyi.zhao@gmail.com auth.el
# Then remove the plain version of the token info.
$ rm auth.el

But I still can't figure out how to let Emacs do the above job for me
automatically when the token file is read by Emacs in an unencrypted
format for the first time.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Transparent encrypt and decrypt token file with gpg2 in Emacs.
  2021-06-10  2:19   ` Hongyi Zhao
@ 2021-06-10  5:08     ` Hongyi Zhao
  0 siblings, 0 replies; 4+ messages in thread
From: Hongyi Zhao @ 2021-06-10  5:08 UTC (permalink / raw)
  To: Hongyi Zhao, help-gnu-emacs

On Thu, Jun 10, 2021 at 10:19 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Thu, Jun 10, 2021 at 12:06 AM Jean Louis <bugs@gnu.support> wrote:
> >
> > * Hongyi Zhao <hongyi.zhao@gmail.com> [2021-06-09 18:28]:
> > > Loading /home/werner/DvdMgr/screen2latex.el.git/auth.el.gpg...
> > > Decrypting /home/werner/DvdMgr/screen2latex.el.git/auth.el.gpg...done
> > > epa-file-insert-file-contents: Opening input file: Can't decrypt, No
> > > data (no armored data); No data (expected a packet but did not find
> > > one); Exit
> > > Mark set [4 times]
> >
> > Send the file for review.
> >
> > If it is encrypted, there should be nothing much to worry... ^‿^
>
> If I first store the plain/unencrypted token info into a file, say,
> named as auth.el, and then encrypt it outside of Emacs with gpg(2) as
> below, the problem will disappear:
>
> $ gpg2 -o auth.el.gpg -e -r hongyi.zhao@gmail.com auth.el
> # Then remove the plain version of the token info.
> $ rm auth.el
>
> But I still can't figure out how to let Emacs do the above job for me
> automatically when the token file is read by Emacs in an unencrypted
> format for the first time.

I figured out the Emacs way of this job based on the wonderful Emacs
manual as described at
<https://www.gnu.org/software/emacs/manual/html_node/epa/Encrypting_002fdecrypting-gpg-files.html>:

<quote>
3.6 Encrypting/decrypting gpg files

By default, every file whose name ends with .gpg will be treated as
encrypted. That is, when you open such a file, the decrypted text is
inserted in the buffer rather than encrypted one. Similarly, when you
save the buffer to a foo.gpg file, encrypted data is written.

The file name pattern for encrypted files can be controlled by
epa-file-name-regexp.
</quote>

Once again, the RTFM philosophy shows its power and enduring value.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-10  5:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-09 15:12 Transparent encrypt and decrypt token file with gpg2 in Emacs Hongyi Zhao
2021-06-09 16:03 ` Jean Louis
2021-06-10  2:19   ` Hongyi Zhao
2021-06-10  5:08     ` Hongyi Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).