Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Oct 18, 2023
1 parent 91441a1 commit 3e690af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
14 changes: 7 additions & 7 deletions pkg/lakego-pkg/go-cryptobin/cryptobin/sm2/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,14 @@ func (this SM2) FromPrivateKeyString(keyString string) SM2 {

// ==========

// 公钥压缩字节, hex 解码后
func (this SM2) FromPublicKeyCompressBytes(pubBytes []byte) SM2 {
this.publicKey = sm2.Decompress(pubBytes[:])
// 公钥压缩字节, hex 或者 base64 解码后
func (this SM2) FromPublicKeyBytes(pubBytes []byte) SM2 {
key := cryptobin_tool.HexEncode(pubBytes)

return this
return this.FromPublicKeyString(key)
}

// 明文私钥生成私钥结构体, hex 解码后
// 明文私钥生成私钥结构体, hex 或者 base64 解码后
func (this SM2) FromPrivateKeyBytes(priBytes []byte) SM2 {
c := sm2.P256Sm2()
k := new(big.Int).SetBytes(priBytes)
Expand Down Expand Up @@ -397,7 +397,7 @@ func FromString(data string) SM2 {

// Base64
func (this SM2) FromBase64String(data string) SM2 {
newData, err := cryptobin_tool.NewEncoding().Base64Decode(data)
newData, err := cryptobin_tool.Base64Decode(data)
if err != nil {
return this.AppendError(err)
}
Expand All @@ -414,7 +414,7 @@ func FromBase64String(data string) SM2 {

// Hex
func (this SM2) FromHexString(data string) SM2 {
newData, err := cryptobin_tool.NewEncoding().HexDecode(data)
newData, err := cryptobin_tool.HexDecode(data)
if err != nil {
return this.AppendError(err)
}
Expand Down
16 changes: 4 additions & 12 deletions pkg/lakego-pkg/go-cryptobin/cryptobin/sm2/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ func (this SM2) GetPrivateKeyCurve() elliptic.Curve {
func (this SM2) GetPrivateKeyDHexString() string {
data := this.privateKey.D

dataHex := cryptobin_tool.
NewEncoding().
HexEncode(data.Bytes())
dataHex := cryptobin_tool.HexEncode(data.Bytes())

return dataHex
}
Expand All @@ -47,9 +45,7 @@ func (this SM2) GetPublicKeyCurve() elliptic.Curve {
func (this SM2) GetPublicKeyXHexString() string {
data := this.publicKey.X

dataHex := cryptobin_tool.
NewEncoding().
HexEncode(data.Bytes())
dataHex := cryptobin_tool.HexEncode(data.Bytes())

return dataHex
}
Expand All @@ -58,9 +54,7 @@ func (this SM2) GetPublicKeyXHexString() string {
func (this SM2) GetPublicKeyYHexString() string {
data := this.publicKey.Y

dataHex := cryptobin_tool.
NewEncoding().
HexEncode(data.Bytes())
dataHex := cryptobin_tool.HexEncode(data.Bytes())

return dataHex
}
Expand All @@ -83,9 +77,7 @@ func (this SM2) GetPublicKeyUncompressString() string {
func (this SM2) GetPublicKeyCompressString() string {
data := sm2.Compress(this.publicKey)

dataHex := cryptobin_tool.
NewEncoding().
HexEncode(data)
dataHex := cryptobin_tool.HexEncode(data)

pre := getPrefix(dataHex[:2])

Expand Down

0 comments on commit 3e690af

Please sign in to comment.