package test

import (
	"applet/app/utils"
	"encoding/base64"
	"fmt"
	"testing"
)

func TestAesCrypt_Encrypt(t *testing.T) {
	var aesCrypt = utils.AesCrypt{
		Key: []byte("e{&[^<wpliI$AgKs:>Ft(.~g]1eR-]VO"),
		Iv:  []byte("ZV`7<5X]/2brS@sz"),
	}

	var text = `{"uid":"82","applyOrder":"821607392542143106","db":{"db_host":"119.23.182.117","db_port":"3306","db_name":"fnuoos_template","db_username":"root","db_password":"Fnuo123com@"}}`
	result, err := aesCrypt.Encrypt([]byte(text))
	if err != nil {
		fmt.Println(err)
		return
	}

	pass64 := base64.StdEncoding.EncodeToString(result)
	fmt.Println(pass64)
}

func TestAesCrypt_Decrypt(t *testing.T) {
	var aesCrypt = utils.AesCrypt{
		Key: []byte("e{&[^<wpliI$AgKs:>Ft(.~g]1eR-]VO"),
		Iv:  []byte("ZV`7<5X]/2brS@sz"),
	}

	pass64 := "JD0RXX1YbZPWKeNiVKsq0jQ1Bfnbln3fIMcmJkovU5gUCf329y9ZdqECWe4OKpoOk25/hPNaBH9VwellhIQhpw=="
	bytesPass, err := base64.StdEncoding.DecodeString(pass64)
	if err != nil {
		fmt.Println(err)
		return
	}

	plainText, err := aesCrypt.Decrypt(bytesPass)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(plainText))
}

func Test_Vi(t *testing.T) {
	fmt.Println("123")
	fmt.Println([]byte("ZV`7<5X]/2brS@sz"))
}
