zhangzengfei
2019-11-21 d5024d00591103b5c4e85e5d25ff3c19b65bd710
licence.go
@@ -1,13 +1,17 @@
package licence
import (
   "encoding/base64"
   "encoding/json"
   "io/ioutil"
   "os"
   "time"
)
/*
   1.0.0 采集机器码, 授权日期 然后 AES 加密, 生成Licence, 秘钥会暴露给客户端
   1.0.1 修改为RSA 非对称加密, 公钥开放. 加密内容为{注册码{机器码+公司+邮箱+手机}+过期时间+授权时间}
   1.0.2 修改Licence文件内容最终为AES加密后的内容, 然后再由公钥解密. 上个版本的bug, 仅使用非对称加密, 用户可以替换公钥
*/
type RegisterCode struct {
   MachineCode string
   Company     string
@@ -28,7 +32,7 @@
   ValidationErrorExpired                            // Signature expired
   ValidationErrorMalformed
   Version = "1.0.1"
   Version = "1.0.2"
   aesKey  = "www.aiotlink.com"
)
@@ -75,9 +79,7 @@
      return "", err
   }
   licenceText := base64.StdEncoding.EncodeToString(licenceHex)
   return licenceText, nil
   return AESEncodeStr(licenceHex, aesKey), nil
}
func DecryptLicence(licencePath, publicKeyPath string) ([]byte, error) {
@@ -114,7 +116,7 @@
      return nil, err
   }
   licenceHex, _ := base64.StdEncoding.DecodeString(string(licenceCode))
   licenceHex := AESDecodeStr(string(licenceCode), aesKey)
   return RSA.PubKeyDECRYPT(licenceHex)
}