aes.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package pb
  2. const (
  3. Authorization = "Authorization"
  4. //配置参数KEY
  5. ConfigAesEncryptParamKey = "aesEncryptConfig"
  6. ConfigApiLogEnableParamKey = "apiLogEnable"
  7. //通用参数
  8. HeaderXNlContentEncoding = "X-NL-Content-Encoding" //返回给客户端的压缩标识
  9. HeaderXNlProductCode = "X-NL-Product-Code" //产品
  10. HeaderXNlCryptoKey = "X-Nl-Crypto-Key" //产品
  11. HeaderXNlCryptoValue = "J4zjl/1t7kSyktxbDvyYlw==" //产品
  12. HeaderXNlDevIp = "X-NL-DEV-IP" //测试IP
  13. HeaderXNlDisabledEncrypt = "X-NL-DEV-DISABLED-ENCRYPT" //加密禁用
  14. //内部参数
  15. InnerHeaderResCompressMethod = "Res-Encrypt-CompressMethod"
  16. InnerHeaderReqEncryptKey = "Req-Encrypt-Key"
  17. InnerHeaderReqEncryptIv = "Req-Encrypt-Iv"
  18. InnerHeaderResEncryptKey = "Res-Encrypt-Key"
  19. InnerHeaderResEncryptIv = "Res-Encrypt-Iv"
  20. InnerHeaderEncryptEnable = "encryptEnable"
  21. InnerHeaderAesDirectEnable = "Aes-Direct-Enable"
  22. InnerHeaderLogEnable = "Log"
  23. InnerHeaderCompressLength = "X-NL-Compress-Length"
  24. InnerHeaderJwtEncryptSecret = "Req-Jwt-Encrypt-Secret"
  25. AesIvLength = 16 //iv 长度
  26. )
  27. type AesConfig struct {
  28. Enable bool `json:"enable"`
  29. AesDirect bool `json:"aesDirect"` //true 时直接用Aes加密解密,false 时用iv+(encryptData(timestamp+encryptData(content)))加密
  30. Compress string `json:"compress"` // 空 or gzip 或者 br
  31. CompressLength int64 `json:"compressLength"` // 压缩判断长度
  32. Request struct {
  33. Key string `json:"key"`
  34. Iv string `json:"iv"`
  35. } `json:"request"`
  36. Response struct {
  37. Key string `json:"key"`
  38. Iv string `json:"iv"`
  39. } `json:"response"`
  40. }
  41. type (
  42. EncryptConfig struct {
  43. Key []byte `json:"key"`
  44. Iv []byte `json:"iv"`
  45. KeyStr string `json:"key_str"`
  46. IvStr string `json:"iv_str"`
  47. }
  48. ProductInfo struct {
  49. Log bool `json:"log"`
  50. EncryptEnable bool
  51. RequestEncryptConfig *EncryptConfig
  52. ResponseEncryptConfig *EncryptConfig
  53. AesDirect bool
  54. CompressMethod string
  55. CompressLength int64 // 压缩判断长度
  56. }
  57. )