We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当前go版本是1.23.4。
func HexToSM2PrivateKey(hexKey string) (*sm2.PrivateKey, error) { // 将 16 进制字符串转换为字节数组 privateKeyBytes, err := hex.DecodeString(hexKey) if err != nil { return nil, fmt.Errorf("failed to decode hex: %w", err) } curve := sm2.P256Sm2() curve.Params() D := new(big.Int).SetBytes(privateKeyBytes) // 根据 D 生成公钥点 (x, y) x, y := curve.ScalarBaseMult(privateKeyBytes) // 生成 sm2 私钥结构 privateKey := &sm2.PrivateKey{ PublicKey: sm2.PublicKey{ Curve: curve, X: x, Y: y, }, D: D, } return privateKey, nil }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
当前go版本是1.23.4。
The text was updated successfully, but these errors were encountered: