def func(self): # Data caches all the keys for get_secret_keys keys = data.get_secret_keys() # Make the message, get the original message = EncryptedMessage(keys) original = data.get_original(msg_type) # Decrypt the encrypted and compare to the original decrypted = message.decrypt(data.get_encrypted(**options)) self.assertEqual(decrypted, original)
def get_decryptor_and_message(key_location, message_location, passphrase): this_dir = os.path.dirname(__file__) master_dir = os.path.join(this_dir, '../../') sys.path = [master_dir] + sys.path from gpglib.structures import EncryptedMessage, Key # Parse the secret key secret_key_location = os.path.join(master_dir, key_location) key = Key(passphrase=passphrase).parse( open(secret_key_location, 'rb').read()) keys = key.key_dict() # Get message we're gonna continously decrypt message_location = os.path.join(master_dir, message_location) message = open(message_location, 'rb').read() return EncryptedMessage(keys=keys), message
from gpglib.structures import EncryptedMessage, Key if __name__ == '__main__': data = open('tests/data/keys/key.secret.rsa.gpg', 'rb').read() key = Key(passphrase='password25') key.parse(data) keys = key.key_dict() print(keys) data = open('tests/data/encrypted/mdc/rsa/aes/zlib/small.gpg', 'rb').read() message = EncryptedMessage(keys) message.decrypt(data) print("Message successfully decrypted data.dump::") print(message.plaintext) data = open('tests/data/encrypted/mdc/rsa/aes/zlib/big.gpg', 'rb').read() message = EncryptedMessage(keys) message.decrypt(data) print("Message successfully decrypted data.big.dump::") print(message.plaintext)