52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package utils
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"testing"
|
|
)
|
|
|
|
func TestCrypt(t *testing.T) {
|
|
aesKey := []byte("123456789012345678901234567890ab")
|
|
msg := "hellasfsafsdsads"
|
|
encryptedMsg, err := AESCBCEncpryt([]byte(msg), aesKey, aesKey[:16])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
decryptedMsg, err := AESCBCDecpryt(encryptedMsg, aesKey, aesKey[:16])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if msg != string(decryptedMsg) {
|
|
t.Fatal("result is wrong")
|
|
}
|
|
}
|
|
|
|
func TestCrypt2(t *testing.T) {
|
|
//aesKey := []byte("123456789012345678901234567890ab")
|
|
//msg := "hellasfsafsdsads"
|
|
//encryptedMsg, err := AESCBCEncpryt([]byte(msg), aesKey, aesKey[:16])
|
|
//if err != nil {
|
|
// t.Fatal(err)
|
|
//}
|
|
encryptedMsg := "f6T3xoXOusWl0CPnNbJdl/5nYbiNDADGhiUdaLtZoU8sb5iKUifnr89PvQRMVIwtjOeJHpXc0kDRrw+z4zrNlOH2N/LcAjg0WOKT19B1s+LBypnfY24zXgaTEOxzPhqooZMDgIM8KvSqoV+iwFtgo7+PBnry7j/GzFSg91CNTWK6JKB6yk+dqg04SrN+Tw/X/Lmhh6fshWkVKTuZovxp/g=="
|
|
sessionKey := "nClNe9ciHfYQZIa5CWtnkg=="
|
|
Base64_DecodeIv := "okoPcc0wFtQUn4E8+ksWZA=="
|
|
|
|
bytesPassMsg, _ := base64.StdEncoding.DecodeString(encryptedMsg)
|
|
Base64_DecodeIv1, _ := base64.StdEncoding.DecodeString(Base64_DecodeIv)
|
|
sessionKey1, _ := base64.StdEncoding.DecodeString(sessionKey)
|
|
|
|
decryptedMsg, err := AESCBC16Decrypt(sessionKey1, Base64_DecodeIv1, bytesPassMsg)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Fatal(string(decryptedMsg))
|
|
|
|
//data, err := AESCBCDecpryt(bytesPass, []byte(sessionKey), []byte(Base64_Decode))
|
|
//if err != nil {
|
|
// t.Fatal(err)
|
|
//}
|
|
//t.Fatal(data)
|
|
|
|
}
|