Skip to content

Commit

Permalink
00
Browse files Browse the repository at this point in the history
  • Loading branch information
lei006 committed Jun 17, 2021
1 parent 8f4e17b commit aaa5b56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
22 changes: 20 additions & 2 deletions examples/licenser/test2.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func test2() {
licenser := licenser_normal.MakeLicenser(appName, appCode, hardsn, pub_key)
lic_data := licenser_normal.MakeLicenserData(appCode, hardsn)

lic_data.AppName = appName
lic_data.CompanyName = CompanyName
lic_data.MaxNum = maxNum
lic_data.Copyright = Copyright
Expand All @@ -46,10 +47,27 @@ func test2() {
} else {

lic_data.Sign = sign
lic_data.PubKey = pub_key
//lic_data.PubKey = pub_key

lic_data_str111, err_json := lic_data.ToJson()
if err_json != nil {
fmt.Println("err_json ", err_json.Error())
continue
}

bret := licenser.SetData(lic_data_str111, func(data *licenser_normal.LicenserData) {

})
if bret != nil {
fmt.Println("-----------text:", lic_data_str)
fmt.Println("-----------pub_key:", pub_key)
fmt.Println("-----------sign:", sign)
}

bret := licenser.EccVerifySign(lic_data_str, sign, pub_key)
fmt.Println("bret =", i, bret)
fmt.Println("------------------------------------------------")
fmt.Println("------------------------------------------------")
fmt.Println("------------------------------------------------")
}
}

Expand Down
39 changes: 6 additions & 33 deletions tools/licenser_normal/licenser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ type Licenser struct {
PublishKey string //公钥
is_demo bool //演示版

Data *LicenserData
callbacks []LicenserUpdateCallback //更新回调列表
Data *LicenserData
}

func MakeLicenser(appname, appcode, hardsn string, publish_key string) *Licenser {
Expand All @@ -41,37 +40,10 @@ func MakeLicenser(appname, appcode, hardsn string, publish_key string) *Licenser
Data: licenserData,
is_demo: true,
}

return licenser
}

/*
func (this *Licenser) LoadFromFile(filename string) error {
data, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
err = this.LoadData(string(data))
return err
}
func (this *Licenser) SaveToFile(filename string) error {
license_str := this.Data.ToString()
err := ioutil.WriteFile(filename, []byte(license_str), 0666) //写入文件(字节数组)
return err
}
*/

func (this *Licenser) SetCallback(cb LicenserUpdateCallback) {
this.callbacks = append(this.callbacks, cb)
}

func (this *Licenser) LoadData(lic_data string) error {
func (this *Licenser) SetData(lic_data string, call_back func(data *LicenserData)) error {

license_data := &LicenserData{}

Expand All @@ -92,9 +64,7 @@ func (this *Licenser) LoadData(lic_data string) error {
this.Data = license_data

// 4. 通知生效
for _, val := range this.callbacks {
val()
}
call_back(license_data)

return nil
}
Expand All @@ -121,6 +91,9 @@ func (this *Licenser) checkData(license_data *LicenserData) error {
text := license_data.ToString()
ret := this.EccVerifySign(text, license_data.Sign, this.PublishKey)
if ret == false {
fmt.Println("text:[", text, "]")
fmt.Println("sign:[", license_data.Sign, "]")
fmt.Println("pub_key:[", this.PublishKey, "]")
return errors.New("验签名失败")
}

Expand Down

0 comments on commit aaa5b56

Please sign in to comment.