Comments (1)
- 如何生成私钥 https://pkg.go.dev/github.com/emmansun/[email protected]/sm2。
- 这个网站https://www.zytool.cn/util/SMUtil 的加密结果C1不符合规范,C1是曲线点,用不压缩的方式的话,首字符应该是04,补上就可以解密了。
- 如何加密,也请参考 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)
- internal/bignat: sync crypto/internal/bigmod: improve verify/encrypt performance
- result of ECB decryption is incomplete HOT 5
- [plugin] Failed to compile as go plugin at buildmode=plugin HOT 3
- [sync sdk] crypto/x509: implement AddCertWithConstraint HOT 2
- [go1.22] crypto/x509: add new OID type and use it in Certificate
- [go1.20] crypto/x509: add support for PKCS8/PKIX X25519 key encodings
- crypto/x509: implement SetFallbackRoots HOT 1
- [go1.21] crypto/x509: surface ReasonCode in RevocationList API
- 0.26 版本 再mac arm上编译不通过 HOT 1
- SM9测试用例数据来源 HOT 2
- sm3: 优化KDF性能-共享哈希Z的中间结果 HOT 1
- sm3: 优化KDF性能-基于SIMD的多路并行(四路) HOT 2
- sm3: 优化KDF性能-AMD64基于AVX2的8路并行 HOT 1
- sync x509 update HOT 2
- Something wrong about Key Gen or/and Curve check HOT 2
- 中金版本支持 HOT 56
- 升级到v0.27.1后报错 slice bounds out of range [128:119] HOT 2
- pkcs7签名算法和bouncycastle的CMSSignedDataGenerator差异问题 HOT 21
- 这么好的库,顶一下 HOT 1
- smx509.CreateCertificate() error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmsm.