fix: add prefix on create key file
| | |
| | | ) |
| | | |
| | | func main() { |
| | | // 生成秘钥和公钥 |
| | | // 生成秘钥和公钥, 参数: 文件前缀 |
| | | if len(os.Args) > 1 && os.Args[1] == "-g" { |
| | | licence.GetRsaKey() |
| | | licence.GetRsaKey("test") |
| | | return |
| | | } |
| | | |
| | |
| | | prikey *rsa.PrivateKey //私钥 |
| | | } |
| | | |
| | | func GetRsaKey() error { |
| | | func GetRsaKey(prefix string) error { |
| | | privateKey, err := rsa.GenerateKey(rand.Reader, 4096) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | x509PrivateKey := x509.MarshalPKCS1PrivateKey(privateKey) |
| | | privateFile, err := os.Create(privateFileName) |
| | | privateFile, err := os.Create(prefix + "-" + privateFileName) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | if err != nil { |
| | | panic(err) |
| | | } |
| | | publicFile, _ := os.Create(publicFileName) |
| | | publicFile, _ := os.Create(prefix + "-" + publicFileName) |
| | | defer publicFile.Close() |
| | | publicBlock := pem.Block{ |
| | | Type: publicKeyPrefix, |