Search code examples
pythonencryptionpgpencryption-asymmetricpython-gnupgp

python-gnupg is encryptin in wrong format


I'm using python-gnupg to perform pgp encryption to a file. However when i encrypt my fie it is showing up in this format (should be in binary)

-----BEGIN PGP MESSAGE-----

hQEOA0hnW5eJyKhrEAP+PV8rczvIFY8GWUEGjZzrV1fJgmq4OPjilQg579f4/rHX
TTMqFWSEREkXt+OtxIOaoXOisGbekt/+n2exlzVe4riO6LBYIgWHtk1miaOn+2lb
PK/XcCGR3/ntM9XAXfGs9C5CVf9dRLX9k9GKhzP6KY44R7ABInandVZCxiaZKqoD
/jMIwy9QiPaSHR0PC9GSRTy8Qr377QHvoh//mAgl+G7jkd/1QJpr6jHs03Qdlgbb
yLJhqUkLRxYhLnslNAVGkZUq76ZqF30t59jSEs/jVJ3UA49K8ge5BX2jeLfMUkQl
R2TBWdFepfoPcwAeMm7FWRCYSJu64RSSwyhJ8+chY1ae0sB/AZ7VTKVeeNSnZdyF
eYW3OCZL7JHAOBcjKGLFD6/j8tJlWzRt4dMg2Zpoqm2sNdyqChLMD1qdfym//HyL
Vu5pHAs94Xty1LRMeD3D91E8ws5N6wwDOcQl178drG3pZKIlBjJwiUGg9k08IRA8
J88IQ6htgjSwCnMIkaw/eHf4/PuOQXkL+jdE+7I3qmqB6jNrD0Sdegeufm7kxb/x
meGTa2fKr3h+0GUYmVNOfwJppVch/NgXsx8OTjCi9s0Ard2cTe927dC0pzs/QUUs
POcfaECl7HklGzP5Mdowp5oViIv+bGzKecdNNXct9XjQqmIcB5PjIoQ0d7RqAmps
HQVmrJmT4v3L/VOVEntbfJ0vU2jriVtJLHdZzPNMYloTwFLQ0o30rBigDel+R3G8
5oZ/yzBTjlmchcFPsRNhdUDzVg==
=+1kb
-----END PGP MESSAGE-----

here is the code i am using

key_data = open('publickey.asc', encoding="utf-8").read()
import_result = gpg.import_keys(key_data)
pprint(import_result.results)

public_keys = gpg.list_keys()
pprint(public_keys)

with open(LOCALFILE, "rb") as f:
    print("encrypting file")
    status = gpg.encrypt_file(f,recipients=["[email protected]"], output="agreatfile.txt.pgp", always_trust=True)
    print('ok: ', status.ok)
    print('status: ', status.status)
    print('stderr: ', status.stderr)

anyone know what i can do so the encryption format doesn't look like a specific message that's encrypted but the entire file? it should look like this when viewed from a text editor

�Hg[��Ȩk��>�l��WO�8n���E�e�   ��S���y6O����T�bJ#�  .�*�(����/�����|S!�)�@]?%���Ͽ�_��[ɞ��/��w7��F�Rc�qD��
�yxcC�h%��@�O�5PԵ4C

Solution

  • turns out after reading the docuementation 😗, that there is an argument i can pass in called armor and i needed to set that to false

        status = gpg.encrypt_file(f,recipients=["[email protected]"], output="agreatfile.txt.pgp", armor='False' always_trust=True)