aes.go 2.2 KB

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