encryptDecrypt.py 415 B

123456789101112131415161718
  1. import OpenPGP
  2. import OpenPGP.Crypto
  3. import sys
  4. wkey = OpenPGP.Message.parse(open('key', 'rb').read())[0]
  5. data = OpenPGP.LiteralDataPacket('This is text.', 'u', 'stuff.txt')
  6. encrypt = OpenPGP.Crypto.Wrapper(data)
  7. encrypted = encrypt.encrypt([wkey])
  8. print list(encrypted)
  9. # Now decrypt it with the same key
  10. decryptor = OpenPGP.Crypto.Wrapper(wkey)
  11. decrypted = decryptor.decrypt(encrypted)
  12. print list(decrypted)