Git Product home page Git Product logo

Comments (1)

emmansun avatar emmansun commented on July 23, 2024
  1. 如何生成私钥 https://pkg.go.dev/github.com/emmansun/[email protected]/sm2。
  2. 这个网站https://www.zytool.cn/util/SMUtil 的加密结果C1不符合规范,C1是曲线点,用不压缩的方式的话,首字符应该是04,补上就可以解密了。
  3. 如何加密,也请参考 https://pkg.go.dev/github.com/emmansun/[email protected]/sm2 相应的Encrypt / EncryptASN1方法。
func TestZyTool(t *testing.T) {
	cipherBytes, _ := hex.DecodeString("045EE0E5D18118C3CE85B8E7E25EF128E5A744CFF45D01A045114BB47C38BB5075F6AC6A885382C601882F5430FE10F7D11394511A93D86CFFCD1F39A0F30E803618672BE57E5F0763DEE53179C80C6DE4D5579B7C2048F061E3810AADF15850DF6C7FBF8EFD7536E554DA4A")
	bytes, _ := hex.DecodeString("4e85afbc996fdc67b4f05880bd9c0d037932649215ae10cf7085720b6571054c")
	d := new(big.Int).SetBytes(bytes)
	// Create private key from *big.Int
	priv := new(PrivateKey)
	priv.Curve = P256()
	priv.D = d
	priv.PublicKey.X, priv.PublicKey.Y = priv.ScalarBaseMult(priv.D.Bytes())
	plaintext, err := priv.Decrypt(rand.Reader, cipherBytes, nil)
	if err != nil {
		t.Fatal(err)
	}
	if string(plaintext) != "hello world" {
		t.Errorf("expected hello world, got %v", string(plaintext))		
	}
}

from gmsm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.