2

I'm having problems getting compression working with Golang's openpgp library. I am trying to encrypt and compress files that are over 2G, so I'm using file buffers, even if that's a horrible practice. A snippet of my code is as follows:

    newPath := path + ".gpg"

    // encrypt string
    fBuf, err := os.OpenFile(newPath, os.O_WRONLY|os.O_CREATE, 0644)
    defer fBuf.Close()
    if err != nil {
        return "", err
    }

    wc, err := openpgp.Encrypt(fBuf, entityList, nil, nil, pgpConfig)
    defer wc.Close()
    if err != nil {
        return "", err
    }

    r, err := os.OpenFile(path, os.O_RDONLY, 0644)
    defer r.Close()
    if err != nil {
        return "", err
    }

    if _, err := io.Copy(wc, r); err != nil {
          return "", err
    }

pgpConfig's definitions is as follows:

var pgpConfig = &packet.Config{
  DefaultCompressionAlgo: packet.CompressionZLIB,
  CompressionConfig: &packet.CompressionConfig{
    Level: 6,
  },
}

Currently, encryption and decryption work exactly as intended, but there is absolutely no compression. I've tried importing the zlib library and using it directly with no luck... Again, encryption and decryption work, but without compression. Any help would be super appreciated!

Thanks!

Michael Miller
  • 399
  • 1
  • 9

1 Answers1

0

It's a bug:

OpenPGP package is frozen and won't accept a fix. Here is a PR:

This is not a library endorsement but I used ProtonMail OpenPGP and it handled compression.

https://github.com/ProtonMail/go-crypto

K.Novichikhin
  • 339
  • 2
  • 8