|
Packit |
d7e8d0 |
#!/usr/bin/env python
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# Copyright (C) 2016 g10 Code GmbH
|
|
Packit |
d7e8d0 |
# Copyright (C) 2005 Igor Belyi <belyi@users.sourceforge.net>
|
|
Packit |
d7e8d0 |
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# This program is free software; you can redistribute it and/or modify
|
|
Packit |
d7e8d0 |
# it under the terms of the GNU General Public License as published by
|
|
Packit |
d7e8d0 |
# the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
d7e8d0 |
# (at your option) any later version.
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# This program is distributed in the hope that it will be useful, but
|
|
Packit |
d7e8d0 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
d7e8d0 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
d7e8d0 |
# General Public License for more details.
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# You should have received a copy of the GNU General Public License
|
|
Packit Service |
30b792 |
# along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
from __future__ import absolute_import, print_function, unicode_literals
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
import sys
|
|
Packit |
d7e8d0 |
import gpg
|
|
Packit |
d7e8d0 |
|
|
Packit Service |
30b792 |
del absolute_import, print_function, unicode_literals
|
|
Packit Service |
30b792 |
|
|
Packit |
d7e8d0 |
with gpg.Context(armor=True) as c:
|
|
Packit |
d7e8d0 |
recipients = []
|
|
Packit |
d7e8d0 |
print("Enter name of your recipient(s), end with a blank line.")
|
|
Packit |
d7e8d0 |
while True:
|
|
Packit |
d7e8d0 |
line = input()
|
|
Packit |
d7e8d0 |
if not line:
|
|
Packit |
d7e8d0 |
break
|
|
Packit |
d7e8d0 |
new = list(c.keylist(line))
|
|
Packit |
d7e8d0 |
if not new:
|
|
Packit |
d7e8d0 |
print("Matched no known keys.")
|
|
Packit |
d7e8d0 |
else:
|
|
Packit |
d7e8d0 |
print("Adding {}.".format(", ".join(k.uids[0].name for k in new)))
|
|
Packit |
d7e8d0 |
recipients.extend(new)
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
if not recipients:
|
|
Packit |
d7e8d0 |
sys.exit("No recipients.")
|
|
Packit |
d7e8d0 |
|
|
Packit Service |
30b792 |
print("Encrypting for {}.".format(", ".join(
|
|
Packit Service |
30b792 |
k.uids[0].name for k in recipients)))
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
ciphertext, _, _ = c.encrypt(b"This is my message,", recipients)
|
|
Packit |
d7e8d0 |
sys.stdout.buffer.write(ciphertext)
|