|
If you have time and are fine with it being a bit dry, you can read RFC4880 [0], the RFC for OpenPGP. This is something I have done some work on (I wrote a basic implementation in an attempt to understand a while ago [1]), but I don't have a nice writeup. An OpenPGP file, whether it is a public key or encrypted file, consists of a list of packets. Generally it is a binary file, but an armored file consists of this binary in base64 and then a checksum.
You can get these packets with
gpg --list-packets <file> Example output from a signed and encrypted file gpg: encrypted with 2048-bit RSA key, ID 09FBFEF359DD186F, created 2016-11-30
"asdfas <sdfasdfasd@asdfasd.asdf>"
# off=0 ctb=85 tag=1 hlen=3 plen=268
:pubkey enc packet: version 3, algo 1, keyid 09FBFEF359DD186F
data: [2047 bits]
# off=271 ctb=d2 tag=18 hlen=3 plen=377 new-ctb
:encrypted data packet:
length: 377
mdc_method: 2
# off=293 ctb=a3 tag=8 hlen=1 plen=0 indeterminate
:compressed packet: algo=2
# off=295 ctb=90 tag=4 hlen=2 plen=13
:onepass_sig packet: keyid 0D3B106118D1EFBE
version 3, sigclass 0x00, digest 8, pubkey 1, last=1
# off=310 ctb=ac tag=11 hlen=2 plen=19
:literal data packet:
mode b (62), created 1480523012, name="file.txt",
raw data: 5 bytes
# off=331 ctb=89 tag=2 hlen=3 plen=284
:signature packet: algo 1, keyid 0D3B106118D1EFBE
version 4, created 1480523012, md5len 0, sigclass 0x00
digest algo 8, begin of digest 05 c4
hashed subpkt 2 len 4 (sig created 2016-11-30)
subpkt 16 len 8 (issuer key ID 0D3B106118D1EFBE)
data: [2046 bits]
The pubkey encrypted packets contain a key used to encrypt the data. The encrypted data packet includes that symmetrically encrypted data.When I have more time, I may do a more useful writeup on my site, but currently I am too busy. [0] https://www.ietf.org/rfc/rfc4880.txt
[1] All I could find was my file parsing code, I dumped it at https://github.com/artemist/mupg |