unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* epg encrypt non interactive
@ 2022-07-06  2:25 GH
  2022-07-06  3:50 ` Emanuel Berg
  2022-07-06  8:42 ` Jean Louis
  0 siblings, 2 replies; 4+ messages in thread
From: GH @ 2022-07-06  2:25 UTC (permalink / raw)
  To: Help GNU Emacs


I want encrypt a string using GPG (epg/epa)

I think that (epg-encrypt-string) is my function to it:


(epg-encrypt-string CONTEXT PLAIN RECIPIENTS &optional SIGN
ALWAYS-TRUST)

Encrypt a string PLAIN.
If RECIPIENTS is nil, it performs symmetric encryption.


(let ((context (epg-make-context 'OpenPGP)))
  (epg-encrypt-string context "hi" "???"))


I need a key as RECIPIENT not symmetric encryption.

RECIPIENTS can be insert interactively easy, for example using:

(epa-select-keys (epg-make-context epa-protocol) ""
"recipient@example.org")

but not so without `interactive'


how can I do? any funct that return a key?



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

* Re: epg encrypt non interactive
  2022-07-06  2:25 epg encrypt non interactive GH
@ 2022-07-06  3:50 ` Emanuel Berg
  2022-07-06  8:42 ` Jean Louis
  1 sibling, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2022-07-06  3:50 UTC (permalink / raw)
  To: help-gnu-emacs

GH wrote:

> how can I do? any funct that return a key?

`epg-list-keys' ?

Use the source, Luke ...

epg is EasyPG BTW and PG is PG as in GPG = GNU Privacy Guard?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: epg encrypt non interactive
  2022-07-06  2:25 epg encrypt non interactive GH
  2022-07-06  3:50 ` Emanuel Berg
@ 2022-07-06  8:42 ` Jean Louis
  2022-07-07 14:33   ` GH
  1 sibling, 1 reply; 4+ messages in thread
From: Jean Louis @ 2022-07-06  8:42 UTC (permalink / raw)
  To: GH; +Cc: Help GNU Emacs

* GH <project@gnuhacker.org> [2022-07-06 05:27]:
> 
> I want encrypt a string using GPG (epg/epa)
> 
> I think that (epg-encrypt-string) is my function to it:
> 
> 
> (epg-encrypt-string CONTEXT PLAIN RECIPIENTS &optional SIGN
> ALWAYS-TRUST)
> 
> Encrypt a string PLAIN.
> If RECIPIENTS is nil, it performs symmetric encryption.

`epg-encrypt-string' does not have proper documentation.

Simple function on my side:

(defun rcd-gpg-encrypt (string receiver)
  "Return the GnuPG STRING encrypted to RECEIVER."
    (if (rcd-which "gpg")
	(rcd-command-output-from-input "gpg" string "-e" "-a" "-r" receiver)
      (rcd-warning-message "RCD ERROR: `gpg' not found in $PATH")))

(defun rcd-command-output-from-input (program input &rest args)
  "Return output string from PROGRAM with given INPUT string and optional ARGS."
  (let* ((output (with-temp-buffer
		   (insert input)
		   (apply #'call-process-region nil nil program t '(t nil) nil args)
		   (buffer-string))))
    output))

To make it simpler:

(defun rcd-gpg-encrypt (string receiver)
  "Return the GnuPG STRING encrypted to RECEIVER."
  (rcd-command-output-from-input "/usr/bin/gpg" string "-e" "-a" "-r" receiver))

(rcd-gpg-encrypt "Hello" "bugs@gnu.support") ⇒ "-----BEGIN PGP MESSAGE-----

hQEMA6Ilx5GnipwAAQf/X8voSGJSuQwvdk2CTMdvvmY4bg2uRu3ajmsBb9vZ05JO
kDc+wi9pdLoC6F3daNeR58yg3OBvPBFsgOWNk8ioS0yux0nhq5s0rSXlBdmQb/ID
A2wO2zS7aN3kVePNeqs8Fqej9fNsAD+HoFk8HdP1eTxevPatrC//1CJudcai8Cum
+IDcuuuR0vCaeAGlOdLJ5tcqxA1vPkSrWBMNbv40gYc74KRt7pw2VZeyMsPZcvOr
C5AKYzDDw/hKGXXr2+LwJjPDJTvCHHuxT+zC/9fMrsHRFlEvT1I+4Y1PgIEpU5kE
+CzAGS7KP/XQulwLNMWBSIaKA1JxsznMHuUxmq0wooUCDAMAAAAAAAAAAAEP/0dl
PDu0VLUcLKAYmqj/lJbETyXpsm2TIy6PMFyVO2faEhV2s1dFb9w2C4/2xk5xhdUz
C1YDDZBf2ZdJjVY9DkQ6oR4TaOV0+IB+RlKum6r0noKxQWZPkRKa+c7k6bl9hJiP
SltUldLxkXwlRizLQy/6OYLR9FmbtJZSBR2vwkyGFKqw6zxtMaMAV6mqJbPfMow1
vbhX6Jpv8ShFVf9VVmlGD8pFjX0l6A9TUXO+YLWdQfKJfdwZoo9PN4vunnsAJpxC
w3qyKiwnlojXPvQP2RJ5lbjPUwc0N8G3GIFSbJZ+SjXdUJCmDTnNwY/os+QfBfNy
76lc3fbJVOKdYPSssLfRZyNVuFKNRXL2TuKVvVj5rPl5sHvn1woVHcHIEiiCKeQ1
MNuFsXlb3lRBzKs1gPbBVusCZa5FwHVJXm267bNhgIjl7e9EwEf495++CU/oyJtp
j2Dmq3mEPKXMmtCgVEJSVSYx7Qq09nbLejSfcfQT33aDkyU2bFoCh7w4aXC4JZyI
U+CBFxK2a8YdLWxQhA2YaFJZRmpG90lQhBybFrhnHMvfzDjJf5EUktFEWi310Idm
61A9ymYrsENoPCgZ8cfJzM9L+zGy2yBwRQi8ud4xL5rF5RNDaXoejZwbQB3JiPpA
35vlIVF7BprWGpdMZdRGOGpVDGxY5fg9TIDcpLBL0kABR/I1W5Gj6pLwDL9w0Glm
/6tlq+NUoCyZhsrVGa3GJI3IQTRO8pqKIRH5ASJj+SJPTlAP5RiZOQCqxCSZdiUe
=KNo5
-----END PGP MESSAGE-----
"


-- 
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: epg encrypt non interactive
  2022-07-06  8:42 ` Jean Louis
@ 2022-07-07 14:33   ` GH
  0 siblings, 0 replies; 4+ messages in thread
From: GH @ 2022-07-07 14:33 UTC (permalink / raw)
  To: Help GNU Emacs

Jean Louis <bugs@gnu.support> writes:
> `epg-encrypt-string' does not have proper documentation.

Works, but I think that I can do it using `epg-encrypt-string', just I
need a function that return the keys

This function based in (epa--select-keys) work but you need type C-c C-c
to return the keys:

#+begin_src elisp

(defun epg-return-key (uid)
  (let* ((context (epg-make-context epa-protocol))
	 (keys (epg-list-keys context uid)))

    (unless (and epa-keys-buffer
		 (buffer-live-p epa-keys-buffer))
      (setq epa-keys-buffer (generate-new-buffer "*Keys*")))

    (save-window-excursion
      (with-current-buffer epa-keys-buffer
	(epa-key-list-mode)
	;; C-c C-c is the usual way to finish the selection (bug#11159).
	(define-key (current-local-map) "\C-c\C-c" 'exit-recursive-edit)
	(let ((inhibit-read-only t)
	      buffer-read-only)
          (erase-buffer)
          (epa--insert-keys keys)
          (setq epa-exit-buffer-function #'abort-recursive-edit)
          (goto-char (point-min))
          (let ((display-buffer-mark-dedicated 'soft))
            (pop-to-buffer (current-buffer))))
	(unwind-protect
	    (progn
	      (recursive-edit)
	      (epa--marked-keys))
          (kill-buffer epa-keys-buffer))))))

(epg-return-key "your@mail.com")

#+end_src

C-c C-c run (exit-recursive-edit), but I dont know how do it without
interaction

Any idea?



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

end of thread, other threads:[~2022-07-07 14:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-06  2:25 epg encrypt non interactive GH
2022-07-06  3:50 ` Emanuel Berg
2022-07-06  8:42 ` Jean Louis
2022-07-07 14:33   ` GH

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).