GAAS 广汽安道拓GFrame金属件MOM项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5 KiB

  1. package utils
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func Test_a(t *testing.T) {
  7. //设置摘要
  8. //明文
  9. origData := []byte("123456")
  10. //加密
  11. en := AESEncrypt(origData)
  12. fmt.Printf("%s, %d, \n", en, len(en))
  13. //encodeString := base64.StdEncoding.EncodeToString(en)
  14. //fmt.Printf("11-> %s\n", encodeString)
  15. //dd, err := base64.StdEncoding.DecodeString(encodeString)
  16. //fmt.Printf("22-> %s, %v\n", string(dd), err)
  17. //if (err != nil) {
  18. // fmt.Printf("22-> %v\n", string(dd))
  19. //}else {
  20. // //log.Fatalf("22-> %v", string(dd))
  21. //}
  22. //de2 := AESDecrypt(dd, key)
  23. ////fmt.Println(string(de))
  24. //fmt.Println(string(de2))
  25. //fmt.Println("-----------------------------")
  26. //for len(en) > 0 {
  27. // ch, size := utf8.DecodeRune(en)
  28. // en = en[size:]
  29. // fmt.Printf("%c ", ch)
  30. //}
  31. //fmt.Println()
  32. //解密
  33. de := AESDecrypt(en)
  34. //fmt.Println(string(de))
  35. fmt.Println(de)
  36. fmt.Println(CheckPWD("123456",
  37. "x04jpoIrc8/mvNRqAG59Wg=="))
  38. fmt.Println("------------------------------------")
  39. }
  40. func TestMd5(t *testing.T) {
  41. b := []byte("1234567890abcdef")
  42. t.Logf("text: %s, md5: %s", b, Md5(b))
  43. }
  44. func TestEncrypt(t *testing.T) {
  45. //要加密的字符串
  46. password := "123456"
  47. // 加密后的string
  48. ciphertext := Encrypt(password)
  49. //ciphertext := "$2a$10$peql3KEqCCCntir0qTe56OJiDNR6EYgUFwPyAcb6xyG1UNoCVRM0G"
  50. t.Logf("ciphertext: %s", ciphertext)
  51. ok, err := CompareHashAndPassword(ciphertext,password)
  52. if err != nil{
  53. t.Error(err)
  54. }
  55. if ok{
  56. t.Logf("密码正确")
  57. }else{
  58. t.Logf("密码错误")
  59. }
  60. }