aes.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. XNlCryptoKey string `json:"xNlCryptoKey"`
  36. Request struct {
  37. Key string `json:"key"`
  38. Iv string `json:"iv"`
  39. } `json:"request"`
  40. Response struct {
  41. Key string `json:"key"`
  42. Iv string `json:"iv"`
  43. } `json:"response"`
  44. }
  45. type (
  46. EncryptConfig struct {
  47. Key []byte `json:"key"`
  48. Iv []byte `json:"iv"`
  49. KeyStr string `json:"key_str"`
  50. IvStr string `json:"iv_str"`
  51. }
  52. ProductInfo struct {
  53. Log bool `json:"log"`
  54. EncryptEnable bool
  55. XNlCryptoKey string `json:"xNlCryptoKey"`
  56. RequestEncryptConfig *EncryptConfig
  57. ResponseEncryptConfig *EncryptConfig
  58. AesDirect bool
  59. CompressMethod string
  60. CompressLength int64 // 压缩判断长度
  61. }
  62. )