package utils

import (
	"fmt"
	"testing"
)

func Test_a(t *testing.T)  {
	//设置摘要
	//明文
	origData := []byte("123456")

	//加密
	en := AESEncrypt(origData)
	fmt.Printf("%s, %d, \n", en, len(en))

	//encodeString := base64.StdEncoding.EncodeToString(en)
	//fmt.Printf("11-> %s\n", encodeString)
	//dd, err := base64.StdEncoding.DecodeString(encodeString)
	//fmt.Printf("22-> %s, %v\n", string(dd), err)
	//if (err != nil) {
	//	fmt.Printf("22-> %v\n", string(dd))
	//}else {
	//	//log.Fatalf("22-> %v", string(dd))
	//}
	//de2 := AESDecrypt(dd, key)
	////fmt.Println(string(de))
	//fmt.Println(string(de2))
	//fmt.Println("-----------------------------")

	//for len(en) > 0 {
	//	ch, size := utf8.DecodeRune(en)
	//	en = en[size:]
	//	fmt.Printf("%c ", ch)
	//}
	//fmt.Println()
	//解密
	de := AESDecrypt(en)
	//fmt.Println(string(de))
	fmt.Println(de)

	fmt.Println(CheckPWD("123456",
		"x04jpoIrc8/mvNRqAG59Wg=="))

	fmt.Println("------------------------------------")

}

func TestMd5(t *testing.T) {
	b := []byte("1234567890abcdef")
	t.Logf("text: %s, md5: %s", b, Md5(b))
}

func TestEncrypt(t *testing.T) {
	//要加密的字符串
	password := "123456"
	// 加密后的string
	ciphertext := Encrypt(password)

	//ciphertext := "$2a$10$peql3KEqCCCntir0qTe56OJiDNR6EYgUFwPyAcb6xyG1UNoCVRM0G"
	t.Logf("ciphertext: %s", ciphertext)

	ok, err := CompareHashAndPassword(ciphertext,password)
	if err != nil{
		t.Error(err)
	}
	if ok{
		t.Logf("密码正确")
	}else{
		t.Logf("密码错误")
	}

}
