package sm4

import (
	"encoding/base64"
	"testing"
)

func TestECBDecrypt(t *testing.T) {
	decode, err := base64.StdEncoding.DecodeString("TfbbYELgZetVpVhhTK31Wg==")
	if err != nil {
		t.Fatalf("decode error: %v", err)
	}
	key := []byte{16, 101, 63, 34, 97, 41, 62, 49, 225, 208, 57, 189, 50, 158, 31, 100}
	//iv := []byte{34, 244, 188, 11, 120, 236, 119, 58, 191, 210, 3, 95, 85, 72, 172, 249}
	plainText, err := ECBDecrypt(key, decode)
	if err != nil {
		t.Fatalf("ecb decrypt error: %v", err)
	}
	t.Log("ecb decrypt result:", string(PKCS5UnPadding(plainText)))
}

func TestCFBEncrypt(t *testing.T) {
	key := []byte{16, 101, 63, 34, 97, 41, 62, 49, 225, 208, 57, 189, 50, 158, 31, 100}
	iv := []byte{34, 244, 188, 11, 120, 236, 119, 58, 191, 210, 3, 95, 85, 72, 172, 249}
	decode, err := base64.StdEncoding.DecodeString("XO9I6k9h2zk/dHSK+zo3Dg==")
	if err != nil {
		t.Fatalf("decode error: %v", err)
	}
	bytes, err := OFBDecrypt(key, iv, decode)
	if err != nil {
		t.Fatalf("ecb decrypt error: %v", err)
	}
	t.Log("ecb decrypt result:", string(PKCS5UnPadding(bytes)))
}
