aes.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. HeaderXRequestTimestamp = "X-Request-Timestamp" //加密禁用
  17. //内部参数
  18. InnerHeaderResCompressMethod = "Res-Encrypt-CompressMethod"
  19. InnerHeaderReqEncryptKey = "Req-Encrypt-Key"
  20. InnerHeaderReqEncryptIv = "Req-Encrypt-Iv"
  21. InnerHeaderResEncryptKey = "Res-Encrypt-Key"
  22. InnerHeaderResEncryptIv = "Res-Encrypt-Iv"
  23. InnerHeaderEncryptEnable = "encryptEnable"
  24. InnerHeaderAesDirectEnable = "Aes-Direct-Enable"
  25. InnerHeaderLogEnable = "Log"
  26. InnerHeaderCompressLength = "X-NL-Compress-Length"
  27. InnerHeaderJwtEncryptSecret = "Req-Jwt-Encrypt-Secret"
  28. AesIvLength = 16 //iv 长度
  29. )
  30. type AesConfig struct {
  31. Enable bool `json:"enable"`
  32. AesDirect bool `json:"aesDirect"` //true 时直接用Aes加密解密,false 时用iv+(encryptData(timestamp+encryptData(content)))加密
  33. Compress string `json:"compress"` // 空 or gzip 或者 br
  34. CompressLength int64 `json:"compressLength"` // 压缩判断长度
  35. Request struct {
  36. Key string `json:"key"`
  37. Iv string `json:"iv"`
  38. } `json:"request"`
  39. Response struct {
  40. Key string `json:"key"`
  41. Iv string `json:"iv"`
  42. } `json:"response"`
  43. }
  44. type (
  45. EncryptConfig struct {
  46. Key []byte `json:"key"`
  47. Iv []byte `json:"iv"`
  48. KeyStr string `json:"key_str"`
  49. IvStr string `json:"iv_str"`
  50. }
  51. ProductInfo struct {
  52. Log bool `json:"log"`
  53. EncryptEnable bool
  54. RequestEncryptConfig *EncryptConfig
  55. ResponseEncryptConfig *EncryptConfig
  56. AesDirect bool
  57. CompressMethod string
  58. CompressLength int64 // 压缩判断长度
  59. }
  60. )