aes_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package service
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "testing"
  7. "encoding/hex"
  8. "go-common/app/job/main/passport-user-compare/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestService_Encrypt(t *testing.T) {
  12. Convey("Encrypt param ", t, func() {
  13. input := []byte("15253340367")
  14. res, err := Encrypt(input, []byte("bili_@F1C2^Y_enc"))
  15. ShouldBeNil(err)
  16. ShouldNotBeNil(res)
  17. fmt.Printf("res is (%+v)\n", res)
  18. fmt.Printf("hex is (%+v) \n", strings.ToUpper(hex.EncodeToString(res)))
  19. })
  20. }
  21. func TestService_Decrypt(t *testing.T) {
  22. Convey("Decrypt param ", t, func() {
  23. var (
  24. in []byte
  25. err error
  26. res []byte
  27. )
  28. sns := &model.OriginAccountSns{
  29. SinaUID: 5208921734,
  30. }
  31. th := &model.UserThirdBind{
  32. OpenID: "5208921734",
  33. }
  34. if s, err1 := strconv.ParseInt(th.OpenID, 10, 64); err1 != nil {
  35. fmt.Printf("error happen %+v", err1)
  36. } else {
  37. fmt.Println(s == sns.SinaUID)
  38. }
  39. a := new(model.UserBase)
  40. fmt.Printf("(%+v)", a == nil)
  41. if in, err = hex.DecodeString("3DEF2C03D0C822C57C5E3A931C087F27"); err != nil {
  42. fmt.Printf("err , (%+v)\n", err)
  43. } else {
  44. fmt.Printf("in, (%+v)\n", in)
  45. }
  46. res, err = Decrypt(in, []byte("bili_@F1C2^Y_enc"))
  47. ShouldBeNil(err)
  48. ShouldNotBeNil(res)
  49. fmt.Printf("(%+v) ,len is %d\n", string(res), len(in))
  50. })
  51. }