passport_util.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import "go-common/app/job/main/passport-encrypt/model"
  3. // EncryptAccount Encrypt Account
  4. func EncryptAccount(a *model.OriginAccount) (res *model.EncryptAccount) {
  5. return &model.EncryptAccount{
  6. Mid: a.Mid,
  7. UserID: a.UserID,
  8. Uname: a.Uname,
  9. Pwd: a.Pwd,
  10. Salt: a.Salt,
  11. Email: a.Email,
  12. Tel: doEncrypt(a.Tel),
  13. CountryID: a.CountryID,
  14. MobileVerified: a.MobileVerified,
  15. Isleak: a.Isleak,
  16. Mtime: a.Mtime,
  17. }
  18. }
  19. // DecryptAccount Decrypt Account
  20. func DecryptAccount(a *model.EncryptAccount) (res *model.OriginAccount) {
  21. return &model.OriginAccount{
  22. Mid: a.Mid,
  23. UserID: a.UserID,
  24. Uname: a.Uname,
  25. Pwd: a.Pwd,
  26. Salt: a.Salt,
  27. Email: a.Email,
  28. Tel: doDecrypt(a.Tel),
  29. CountryID: a.CountryID,
  30. MobileVerified: a.MobileVerified,
  31. Isleak: a.Isleak,
  32. Mtime: a.Mtime,
  33. }
  34. }
  35. func doEncrypt(param string) []byte {
  36. var (
  37. err error
  38. res = make([]byte, 0)
  39. )
  40. if param == "" || len(param) == 0 {
  41. return nil
  42. }
  43. input := []byte(param)
  44. if res, err = Encrypt(input); err != nil {
  45. return input
  46. }
  47. return res
  48. }
  49. func doDecrypt(param []byte) string {
  50. var (
  51. err error
  52. res = make([]byte, 0)
  53. )
  54. if param == nil {
  55. return ""
  56. }
  57. input := []byte(param)
  58. if res, err = Decrypt(input); err != nil {
  59. return string(param)
  60. }
  61. return string(res)
  62. }