How to use the pgpy.PGPMessage.from_blob function in PGPy

To help you get started, we’ve selected a few PGPy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github quedexnet / python-api / tests / test_user_stream.py View on Github external
def decrypt_verify(message, private_key, public_key):
  decrypted = private_key.decrypt(pgpy.PGPMessage.from_blob(message))
  if not public_key.verify(decrypted):
    raise AssertionError('Verification failed for message: ' + decrypted)
  return json.loads(decrypted.message)
github leapcode / soledad / tests / e2e / utils.py View on Github external
def get_received_secret(key, fd):
    print("decoding incoming blob to get the secret")
    encrypted = pgpy.PGPMessage.from_blob(fd.read())
    decrypted = key.decrypt(encrypted)
    doc_content = json.loads(decrypted.message)
    content = doc_content['content']
    email_message = email.message_from_string(content)
    received_secret = email_message.get_payload().strip()
    return received_secret
github trustcrypto / python-onlykey / tests / decrypt_PGP_message.py View on Github external
print 'Paste OpenPGP Message, press Ctrl+D or Ctrl+Z(Windows only) when finished'
print

msg_blob = sys.stdin.read()

print 'Do you want to sign or decrypt the message?'
print 's=sign, d=decrypt'
print

action = raw_input()

# PGPMessage will automatically determine if this is a cleartext message or not
# message_from_file = pgpy.PGPMessage.from_file("path/to/a/message")
if action == 's':
    message_from_blob = pgpy.PGPMessage.from_blob(msg_blob)
    print
    print 'Message=', repr(message_from_blob)
    #with priv_key.unlock("test"):
    signed_message |= priv_key.sign(message_from_blob)
    print
    print 'Message with signature =', repr(signed_message)

if action == 'd':
    message_from_blob = pgpy.PGPMessage.from_blob(msg_blob)
    print
    print 'Message=', repr(message_from_blob)
    #with priv_key.unlock("test"):
    decrypted_message = priv_key.decrypt(message_from_blob)
        #decrypted_message2 = priv_key.parse(decrypted_message)
        #decrypted_message3 = priv_key.bytes_to_text(message_from_blob)
    print
github trustcrypto / python-onlykey / tests / PGP_message.py View on Github external
print 'Encoded Signed Message ='
    #print
    #sign_bytes = message_from_blob.__bytes__()
    #print 'Message Bytes=', repr(sign_bytes)
    #print
    sign_text = str(message_from_blob)
    print msg_blob, sign_text
    print
    #print 'Decoded Signed Message =', str(sign_bytes)
if action == 'd':
    #pub_key = makepub()
    print
    print 'Paste OpenPGP Message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)'
    print
    msg_blob = sys.stdin.read()
    message_from_blob = pgpy.PGPMessage.from_blob(msg_blob)
    print
    print 'Message=', repr(message_from_blob)
    #with priv_key.unlock("test"):
    decrypted_message = priv_key.decrypt(message_from_blob)
        #decrypted_message2 = priv_key.parse(decrypted_message)
        #decrypted_message3 = priv_key.bytes_to_text(message_from_blob)
    print
    dec_bytes = decrypted_message.__bytes__()
    print 'Decoded Decrypted Message =', str(dec_bytes)
    print
    dec_text = str(decrypted_message)
    print 'Encoded Decrypted Message ='
    print dec_text
github trustcrypto / python-onlykey / tests / PGP_message.py View on Github external
if action2 == 't':
        print
        print 'Type or paste the text message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)'
        print
        msg_blob = sys.stdin.read()
        message_from_blob = priv_key.sign2(msg_blob)
        print 'Encoded Signed Message ='
        print '-----BEGIN PGP SIGNED MESSAGE-----'
        print 'Hash: SHA256'
        print
    if action2 == 'p':
        print
        print 'Paste OpenPGP Message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)'
        print
        msg_blob = sys.stdin.read()
        message_from_blob = pgpy.PGPMessage.from_blob(msg_blob)
        print
        print 'Message=', repr(message_from_blob)
        message_from_blob |= priv_key.sign2(message_from_blob)
        print 'Encoded Signed Message ='
    #print
    #sign_bytes = message_from_blob.__bytes__()
    #print 'Message Bytes=', repr(sign_bytes)
    #print
    sign_text = str(message_from_blob)
    print msg_blob, sign_text
    print
    #print 'Decoded Signed Message =', str(sign_bytes)
if action == 'd':
    #pub_key = makepub()
    print
    print 'Paste OpenPGP Message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)'
github quedexnet / python-api / end_to_end_tests / test_api_end_to_end.py View on Github external
def decrypt_verify(message):
  decrypted = exchange_key.decrypt(pgpy.PGPMessage.from_blob(message))
  if not trader_key.verify(decrypted):
    raise AssertionError('Verification failed for message: ' + decrypted)
  return json.loads(decrypted.message)
github hpk42 / muacrypt / core / autocrypt / pgpycrypto.py View on Github external
def decrypt(self, enc_data):
        if isinstance(enc_data, str):
            enc_msg = PGPMessage.from_blob(enc_data)
        else:
            enc_msg = enc_data
        keyhandle = enc_msg.issuers.pop()
        skey = self._get_key_from_keyhandle(keyhandle)
        out = skey.decrypt(enc_msg)
        keyinfos = []
        keyinfos.append(KeyInfo(skey.key_algorithm.name, skey.key_size,
                                skey.fingerprint.keyid, skey.userids[0].name,
                                skey.created))
        return six.b(out.message), keyinfos