Updated encrypt-to-all

* Changed plaintext string to byte literal.
* Nested key selection in a try/except statement in case of
  UnicodeEncodeError instances.
* Tested successfully on over 9,000 keys.
This commit is contained in:
Ben McGinnes 2015-05-17 04:03:49 +10:00
parent 24c738f5bb
commit 1c87ecb86a

View File

@ -18,9 +18,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
This program will try to encrypt a simple message to each key on your keyring. This program will try to encrypt a simple message to each key on your
If your keyring has any invalid keys on it, those keys will be removed keyring. If your keyring has any invalid keys on it, those keys will
and it will re-try the encryption.""" be skipped and it will re-try the encryption."""
from pyme import core from pyme import core
from pyme.core import Data, Context from pyme.core import Data, Context
@ -28,7 +28,7 @@ from pyme.constants import validity
core.check_version(None) core.check_version(None)
plain = Data('This is my message.') plain = Data(b'This is my message.')
c = Context() c = Context()
c.set_armor(1) c.set_armor(1)
@ -41,16 +41,19 @@ def sendto(keylist):
names = [] names = []
for key in c.op_keylist_all(None, 0): for key in c.op_keylist_all(None, 0):
print(" *** Found key for %s" % key.uids[0].uid) try:
valid = 0 print(" *** Found key for %s" % key.uids[0].uid)
for subkey in key.subkeys: valid = 0
keyid = subkey.keyid for subkey in key.subkeys:
if keyid == None: keyid = subkey.keyid
break if keyid == None:
can_encrypt = subkey.can_encrypt break
valid += can_encrypt can_encrypt = subkey.can_encrypt
print(" Subkey %s: encryption %s" % \ valid += can_encrypt
(keyid, can_encrypt and "enabled" or "disabled")) print(" Subkey %s: encryption %s" % \
(keyid, can_encrypt and "enabled" or "disabled"))
except UnicodeEncodeError as e:
print(e)
if valid: if valid:
names.append(key) names.append(key)