Files
xgcl/sm/sm2/sm2_pkcs7_test.go
2026-05-27 23:03:00 +08:00

25 lines
494 B
Go

package sm2
import (
"testing"
"github.com/stretchr/testify/assert"
"xdx.jelly/xgcl/grand"
)
// Test Cipher
func TestCipherP7(t *testing.T) {
sk, _ := GenerateKey(Curve(), grand.Reader)
data := make([]byte, 48)
cipher, _ := Encrypt(&sk.PublicKey, data, grand.GetRandom(32))
b, err := cipher.MarshalASN1()
assert.Nil(t, err)
var cipher2 Cipher
b, err = cipher2.UnmarshalASN1(b)
assert.Equal(t, len(b), 0)
assert.Nil(t, err)
assert.Equal(t, cipher.String(), cipher2.String())
}