func Compress(payload string, alg string, enc string, zip string, key interface{}) (token string, err error) {
	if zipAlg, ok := jwcCompressors[zip]; ok {
		compressed := zipAlg.Compress([]byte(payload))
		jwtHeader := map[string]interface{}{
			"enc": enc,
			"alg": alg,
			"zip": zip,
		}
		return encrypt(compressed, jwtHeader, key)
	}
	return "", errors.New(fmt.Sprintf("jwt.Compress(): Unknown compression method '%v'", zip))
}
This method is DEPRICATED and subject to be removed in next version.
Use Encrypt(..) with Zip option instead.

Compress produces encrypted & comressed JWT token given arbitrary payload, key management , encryption and compression algorithms to use (see constants for list of supported algs) and management key.
Management key is of different type for different key management alg, see specific
key management alg implementation documentation.

It returns 5 parts encrypted & compressed JWT token as string and not nil error if something went wrong.
package jose
import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/dvsekhvalnov/jose2go/compact"
)
const (
	NONE = "none"  
	HS256 = "HS256"  
	HS384 = "HS384"  
	HS512 = "HS512"  
	RS256 = "RS256"  
	RS384 = "RS384"  
	RS512 = "RS512"  
	PS256 = "PS256"  
	PS384 = "PS384"  
	PS512 = "PS512"  
	ES256 = "ES256"  
	ES384 = "ES384"  
	ES512 = "ES512"  
	A128CBC_HS256 = "A128CBC-HS256"  
	A192CBC_HS384 = "A192CBC-HS384"  
	A256CBC_HS512 = "A256CBC-HS512"  
	A128GCM       = "A128GCM"        
	A192GCM       = "A192GCM"        
	A256GCM       = "A256GCM"        
	DIR                = "dir"                 
	RSA1_5             = "RSA1_5"              
	RSA_OAEP           = "RSA-OAEP"            
	RSA_OAEP_256       = "RSA-OAEP-256"        
	A128KW             = "A128KW"              
	A192KW             = "A192KW"              
	A256KW             = "A256KW"              
	A128GCMKW          = "A128GCMKW"           
	A192GCMKW          = "A192GCMKW"           
	A256GCMKW          = "A256GCMKW"           
	PBES2_HS256_A128KW = "PBES2-HS256+A128KW"  
	PBES2_HS384_A192KW = "PBES2-HS384+A192KW"  
	PBES2_HS512_A256KW = "PBES2-HS512+A256KW"  
	ECDH_ES            = "ECDH-ES"             
	ECDH_ES_A128KW     = "ECDH-ES+A128KW"      
	ECDH_ES_A192KW     = "ECDH-ES+A192KW"      
	ECDH_ES_A256KW     = "ECDH-ES+A256KW"      
	DEF = "DEF"  
)
var jwsHashers = map[string]JwsAlgorithm{}
var jweEncryptors = map[string]JweEncryption{}
var jwaAlgorithms = map[string]JwaAlgorithm{}
var jwcCompressors = map[string]JwcAlgorithm{}
func RegisterJwe(alg JweEncryption) {
	jweEncryptors[alg.Name()] = alg
}
func RegisterJwa(alg JwaAlgorithm) {
	jwaAlgorithms[alg.Name()] = alg
}
func RegisterJws(alg JwsAlgorithm) {
	jwsHashers[alg.Name()] = alg
}
func RegisterJwc(alg JwcAlgorithm) {
	jwcCompressors[alg.Name()] = alg
}
type JweEncryption interface {
	Encrypt(aad, plainText, cek []byte) (iv, cipherText, authTag []byte, err error)
	Decrypt(aad, cek, iv, cipherText, authTag []byte) (plainText []byte, err error)
	KeySizeBits() int
	Name() string
}
type JwaAlgorithm interface {
	WrapNewKey(cekSizeBits int, key interface{}, header map[string]interface{}) (cek []byte, encryptedCek []byte, err error)
	Unwrap(encryptedCek []byte, key interface{}, cekSizeBits int, header map[string]interface{}) (cek []byte, err error)
	Name() string
}
type JwsAlgorithm interface {
	Verify(securedInput, signature []byte, key interface{}) error
	Sign(securedInput []byte, key interface{}) (signature []byte, err error)
	Name() string
}
type JwcAlgorithm interface {
	Compress(plainText []byte) []byte
	Decompress(compressedText []byte) []byte
	Name() string
}
func Zip(alg string) func(cfg *JoseConfig) {
	return func(cfg *JoseConfig) {
		cfg.CompressionAlg = alg
	}
}
func Header(name string, value interface{}) func(cfg *JoseConfig) {
	return func(cfg *JoseConfig) {
		cfg.Headers[name] = value
	}
}
func Headers(headers map[string]interface{}) func(cfg *JoseConfig) {
	return func(cfg *JoseConfig) {
		for k, v := range headers {
			cfg.Headers[k] = v
		}
	}
}
type JoseConfig struct {
	CompressionAlg string
	Headers        map[string]interface{}
}
func Sign(payload string, signingAlg string, key interface{}, options ...func(*JoseConfig)) (token string, err error) {
	return SignBytes([]byte(payload), signingAlg, key, options...)
}
func SignBytes(payload []byte, signingAlg string, key interface{}, options ...func(*JoseConfig)) (token string, err error) {
	if signer, ok := jwsHashers[signingAlg]; ok {
		cfg := &JoseConfig{CompressionAlg: "", Headers: make(map[string]interface{})}
		for _, option := range options {
			option(cfg)
		}
		cfg.Headers["alg"] = signingAlg
		paloadBytes := payload
		var header []byte
		var signature []byte
		if header, err = json.Marshal(cfg.Headers); err == nil {
			securedInput := []byte(compact.Serialize(header, paloadBytes))
			if signature, err = signer.Sign(securedInput, key); err == nil {
				return compact.Serialize(header, paloadBytes, signature), nil
			}
		}
		return "", err
	}
	return "", errors.New(fmt.Sprintf("jwt.Sign(): unknown algorithm: '%v'", signingAlg))
}
func Encrypt(payload string, alg string, enc string, key interface{}, options ...func(*JoseConfig)) (token string, err error) {
	return EncryptBytes([]byte(payload), alg, enc, key, options...)
}
func EncryptBytes(payload []byte, alg string, enc string, key interface{}, options ...func(*JoseConfig)) (token string, err error) {
	cfg := &JoseConfig{CompressionAlg: "", Headers: make(map[string]interface{})}
	for _, option := range options {
		option(cfg)
	}
	cfg.Headers["alg"] = alg
	cfg.Headers["enc"] = enc
	byteContent := payload
	if cfg.CompressionAlg != "" {
		if zipAlg, ok := jwcCompressors[cfg.CompressionAlg]; ok {
			byteContent = zipAlg.Compress([]byte(payload))
			cfg.Headers["zip"] = cfg.CompressionAlg
		} else {
			return "", errors.New(fmt.Sprintf("jwt.Compress(): Unknown compression method '%v'", cfg.CompressionAlg))
		}
	} else {
		delete(cfg.Headers, "zip")  
	}
	return encrypt(byteContent, cfg.Headers, key)
}