34 lines
940 B
Go
34 lines
940 B
Go
package sm2a
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"xdx.jelly/xgcl/grand"
|
|
"xdx.jelly/xgcl/sm/sm2"
|
|
)
|
|
|
|
func TestDec(t *testing.T) {
|
|
clientKeyCtx := NewClientEncKeyGenContext()
|
|
buf, _ := clientKeyCtx.ClientKeyGen_one(grand.Reader)
|
|
ds, pk, buf, _ := ServerEncKeyGen(buf, grand.Reader)
|
|
clientKeyCtx.ClientKeyGen_two(buf)
|
|
dc := clientKeyCtx.ClientKey
|
|
printLog("客户端私钥分量", clientKeyCtx.ClientKey.Bytes())
|
|
printLog("客户端公", clientKeyCtx.Pubkey.Bytes())
|
|
printLog("服务端公", pk.Bytes())
|
|
printLog("服务端私钥分", ds.Bytes())
|
|
|
|
msg := []byte("1234567812345678")
|
|
k := grand.GetRandom(sm2.ByteSize())
|
|
cipher, _ := sm2.Encrypt(pk, msg, k)
|
|
printLog("密文", cipher.Bytes())
|
|
|
|
clientDecCtx := NewClientDecContext()
|
|
buf, _ = clientDecCtx.Decrypt_one(cipher)
|
|
printLog("C1=", buf)
|
|
buf, _ = ServerDecrypt(buf, ds)
|
|
printLog("[ds]C1=", buf)
|
|
plain, _ := clientDecCtx.Decrypt_two(buf, dc)
|
|
printLog("协同解密原文", plain)
|
|
}
|