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{})}

	//apply extra options
	for _, option := range options {
		option(cfg)
	}

	//make sure required headers are managed by us
	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") //we not allow to manage 'zip' header manually for encryption
	}

	return encrypt(byteContent, cfg.Headers, key)
}
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)
}
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 { } ) } //apply extra options for _ , option := range options { option ( cfg ) } //make sure required headers are managed by us cfg . Headers [ " " ] = alg cfg . Headers [ " " ] = enc byteContent := payload if cfg . CompressionAlg != " " { if zipAlg , ok := jwcCompressors [ cfg . CompressionAlg ] ; ok { byteContent = zipAlg . Compress ( [ ] byte ( payload ) ) cfg . Headers [ " " ] = cfg . CompressionAlg } else { return " " , errors . New ( fmt . Sprintf ( " " , cfg . CompressionAlg ) ) } } else { delete ( cfg . Headers , " " ) //we not allow to manage 'zip' header manually for encryption } return encrypt ( byteContent , cfg . Headers , key ) }
// Encrypt produces encrypted JWT token given arbitrary binary payload, key management and encryption 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 JWT token as string and not nil error if something went wrong.
Encrypt produces encrypted JWT token given arbitrary binary payload key management and encryption 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 JWT token as string and not nil error if something went wrong .