#!/usr/bin/env python # decrypt.py - decrypt an encrypted message, given as ascii armored stuff # on stdin # # Encrypted message could be created with simple.py, e.g. # If "gpgsm --decrypt ; echo" groks it, this script should grok it. # # Apart from setting up your keys and certificates, this generally needs: # # export GPG_TTY=`tty` # eval `gpg-agent --daemon --use-standard-socket` # # ascii armored stuff generally has a leading line # -----BEGIN ENCRYPTED MESSAGE----- # based upon: $Id: simple.py,v 1.4 2005/05/17 16:49:28 belyi Exp $ # Copyright (C) 2005 Igor Belyi # Copyright (C) 2002 John Goerzen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys from pyme import core, constants, errors import pyme.constants.validity # Set up our input and output buffers. plain = core.Data() cipher = core.Data(sys.stdin.read()) # Initialize our context. c = core.Context() c.set_armor(1) c.set_protocol(pyme.util.gpgme.GPGME_PROTOCOL_CMS) # Do the decryption. try: c.op_decrypt(cipher, plain) plain.seek(0,0) print plain.read() except errors.GPGMEError, ex: print ex.getstring()