How to use the pgpy.constants.CompressionAlgorithm 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 trustcrypto / python-onlykey / tests / PGP_message.py View on Github external
print 'Enter slot number to use (1 - 4) or enter 0 to list key labels'
    print
    slot = int(raw_input())
    ok.slot(slot)


# 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':
    priv_key = makekey()
    uid = pgpy.PGPUID.new('Nikola Tesla')
    #uid._parent = priv_key
    priv_key.add_uid(uid, usage={KeyFlags.Sign, KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage},
                 hashes=[HashAlgorithm.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512, HashAlgorithm.SHA224],
                 ciphers=[SymmetricKeyAlgorithm.AES256, SymmetricKeyAlgorithm.AES192, SymmetricKeyAlgorithm.AES128],
                 compression=[CompressionAlgorithm.ZLIB, CompressionAlgorithm.BZ2, CompressionAlgorithm.ZIP, CompressionAlgorithm.Uncompressed],
                 key_expires=timedelta(days=365))

    print
    print 'Do you want to sign a text message or add signature to a PGP Message?'
    print 't = text message, p = PGP Message'
    print
    action2 = raw_input()
    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'
github SecurityInnovation / PGPy / tests / test_05_actions.py View on Github external
uid = PGPUID.new('Abraham Lincoln', comment='Honest Abe', email='abraham.lincoln@whitehouse.gov')
    with open('tests/testdata/abe.jpg', 'rb') as abef:
        abebytes = bytearray(os.fstat(abef.fileno()).st_size)
        abef.readinto(abebytes)
    uphoto = PGPUID.new(abebytes)

    # Abe is pretty oldschool, so he uses a DSA primary key
    # normally he uses an ElGamal subkey for encryption, but PGPy doesn't support that yet, so he's settled for RSA for now
    key = PGPKey.new(PubKeyAlgorithm.DSA, 1024)
    subkey = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 1024)

    key.add_uid(uid,
                usage={KeyFlags.Certify, KeyFlags.Sign},
                hashes=[HashAlgorithm.SHA224, HashAlgorithm.SHA1],
                ciphers=[SymmetricKeyAlgorithm.AES128, SymmetricKeyAlgorithm.Camellia128, SymmetricKeyAlgorithm.CAST5],
                compression=[CompressionAlgorithm.ZLIB])
    key.add_uid(uphoto)
    key.add_subkey(subkey, usage={KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage})
    return key
github leapcode / soledad / tests / e2e / utils.py View on Github external
def gen_key(username):
    print("generating OpenPGP key pair")
    key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 4096)
    uid = pgpy.PGPUID.new(username, email='%s@%s' % (username, _provider))
    key.add_uid(
        uid,
        usage={KeyFlags.EncryptCommunications},
        hashes=[HashAlgorithm.SHA512],
        ciphers=[SymmetricKeyAlgorithm.AES256],
        compression=[CompressionAlgorithm.Uncompressed]
    )
    return key
github SecurityInnovation / PGPy / pgpy / pgp.py View on Github external
:type cleartext: ``bool``
        :keyword sensitive: if True, the filename will be set to '_CONSOLE' to signal other OpenPGP clients to treat
                            this message as being 'for your eyes only'. Ignored if cleartext is True.
        :type sensitive: ``bool``
        :keyword format: Set the message format identifier. Ignored if cleartext is True.
        :type format: ``str``
        :keyword compression: Set the compression algorithm for the new message.
                              Defaults to :py:obj:`CompressionAlgorithm.ZIP`. Ignored if cleartext is True.
        :keyword encoding: Set the Charset header for the message.
        :type encoding: ``str`` representing a valid codec in codecs
        """
        # TODO: have 'codecs' above (in :type encoding:) link to python documentation page on codecs
        cleartext = kwargs.pop('cleartext', False)
        format = kwargs.pop('format', None)
        sensitive = kwargs.pop('sensitive', False)
        compression = kwargs.pop('compression', CompressionAlgorithm.ZIP)
        file = kwargs.pop('file', False)
        charset = kwargs.pop('encoding', None)

        filename = ''
        mtime = datetime.utcnow()

        msg = PGPMessage()

        if charset:
            msg.charset = charset

        # if format in 'tu' and isinstance(message, (six.binary_type, bytearray)):
        #     # if message format is text or unicode and we got binary data, we'll need to transcode it to UTF-8
        #     message =

        if file and os.path.isfile(message):
github SecurityInnovation / PGPy / pgpy / packet / packets.py View on Github external
def calg_int(self, val):
        self._calg = CompressionAlgorithm(val)
github hpk42 / muacrypt / core / autocrypt / pgpycrypto.py View on Github external
from pgpy.constants import (CompressionAlgorithm, HashAlgorithm, KeyFlags,
                            PubKeyAlgorithm, SymmetricKeyAlgorithm)

# TODO: these two functions should be in a separate file
from .bingpg import KeyInfo, b64encode_u


# NOTE: key size was decided to be 2048
KEY_SIZE = 2048
# TODO: see which defaults we would like here
SKEY_ARGS = {
    'hashes': [HashAlgorithm.SHA512, HashAlgorithm.SHA256],
    'ciphers': [SymmetricKeyAlgorithm.AES256,
                SymmetricKeyAlgorithm.AES192,
                SymmetricKeyAlgorithm.AES128],
    'compression': [CompressionAlgorithm.ZLIB,
                    CompressionAlgorithm.BZ2,
                    CompressionAlgorithm.ZIP,
                    CompressionAlgorithm.Uncompressed]
}
# RSAEncrypt is deprecated, therefore using RSAEncryptOrSign
# also for the subkey
SKEY_ALG = PubKeyAlgorithm.RSAEncryptOrSign
SKEY_USAGE_SIGN = {KeyFlags.Sign}
SKEY_USAGE_ENC = {KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage}
SKEY_USAGE_ALL = {KeyFlags.Sign, KeyFlags.EncryptCommunications,
                  KeyFlags.EncryptStorage}


def key_bytes(pgpykey):
    """Key bytes.
github hpk42 / muacrypt / core / autocrypt / pgpycrypto.py View on Github external
# TODO: these two functions should be in a separate file
from .bingpg import KeyInfo, b64encode_u


# NOTE: key size was decided to be 2048
KEY_SIZE = 2048
# TODO: see which defaults we would like here
SKEY_ARGS = {
    'hashes': [HashAlgorithm.SHA512, HashAlgorithm.SHA256],
    'ciphers': [SymmetricKeyAlgorithm.AES256,
                SymmetricKeyAlgorithm.AES192,
                SymmetricKeyAlgorithm.AES128],
    'compression': [CompressionAlgorithm.ZLIB,
                    CompressionAlgorithm.BZ2,
                    CompressionAlgorithm.ZIP,
                    CompressionAlgorithm.Uncompressed]
}
# RSAEncrypt is deprecated, therefore using RSAEncryptOrSign
# also for the subkey
SKEY_ALG = PubKeyAlgorithm.RSAEncryptOrSign
SKEY_USAGE_SIGN = {KeyFlags.Sign}
SKEY_USAGE_ENC = {KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage}
SKEY_USAGE_ALL = {KeyFlags.Sign, KeyFlags.EncryptCommunications,
                  KeyFlags.EncryptStorage}


def key_bytes(pgpykey):
    """Key bytes.

    :param key: key (either public or private)
    :type key: PGPKey
    :return: key bytes
github SecurityInnovation / PGPy / pgpy / pgp.py View on Github external
def __init__(self):
        """
        PGPMessage objects represent OpenPGP message compositions.

        PGPMessage implements the `__str__` method, the output of which will be the message composition in
        OpenPGP-compliant ASCII-armored format.

        PGPMessage implements the `__bytes__` method, the output of which will be the message composition in
        OpenPGP-compliant binary format.

        Any signatures within the PGPMessage that are marked as being non-exportable will not be included in the output
        of either of those methods.
        """
        super(PGPMessage, self).__init__()
        self._compression = CompressionAlgorithm.Uncompressed
        self._message = None
        self._mdc = None
        self._signatures = SorteDeque()
        self._sessionkeys = []