This commit is contained in:
kony
2024-12-29 11:00:52 +08:00
parent f5b676e9ee
commit 18e5b5c5e0
4 changed files with 22 additions and 8 deletions

1
go.mod
View File

@@ -19,6 +19,7 @@ require (
fyne.io/systray v1.11.0 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/bmizerany/pq v0.0.0-20131128184720-da2b95e392c1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v1.1.0 // indirect

2
go.sum
View File

@@ -55,6 +55,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/bmizerany/pq v0.0.0-20131128184720-da2b95e392c1 h1:1clOQIolnXGoH1SUo8ZPgdfOWFp/6i8NuRerrVL/TAc=

View File

@@ -7,6 +7,7 @@ import (
"log"
"goodlink/theme"
"goodlink/tools"
"goodlink/ui2"
_ "embed"
@@ -18,6 +19,7 @@ import (
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/atotto/clipboard"
)
var (
@@ -65,13 +67,18 @@ func main() {
}
keyValidated = widget.NewEntry()
keyValidated.SetPlaceHolder("自定义16-32长度字符串")
keyValidated.SetPlaceHolder("自定义16-32字节长度")
key_create_button := widget.NewButton("生成密钥", func() {
keyValidated.SetText(tools.RandomString(16))
})
key_copy_button := widget.NewButton("复制密钥", func() {
clipboard.WriteAll(keyValidated.Text)
})
key_paste_button := widget.NewButton("粘贴密钥", func() {
if s, err := clipboard.ReadAll(); err == nil {
keyValidated.SetText(s)
}
})
localUI := ui2.NewLocalUI(&myWindow)

View File

@@ -2,18 +2,22 @@ package tools
import (
"crypto/rand"
"encoding/base64"
"io"
"math/big"
"net"
)
func RandomString(length int) string {
k := make([]byte, length)
_, err := io.ReadFull(rand.Reader, k)
if err != nil {
panic(err.Error())
bytes := make([]byte, length)
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for i := 0; i < length; {
bint, err := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
if err != nil {
return ""
}
bytes[i] = charset[bint.Int64()]
i++
}
return base64.StdEncoding.EncodeToString(k)
return string(bytes)
}
// 检测未使用的端口