Files
RemLink/internal/overlay/clientwg/key.go
T
qsc20001102 142e5dc7d6
ci / Go checks (ubuntu-latest) (push) Has been cancelled
ci / Go checks (windows-latest) (push) Has been cancelled
初版功能完成
2026-08-29 13:12:17 +08:00

21 lines
497 B
Go

package clientwg
import (
"encoding/base64"
"fmt"
)
// ParseKeyBase64 parses the standard WireGuard 32-byte base64 key format.
func ParseKeyBase64(value string) (Key, error) {
var key Key
decoded, err := base64.StdEncoding.DecodeString(value)
if err != nil {
return key, fmt.Errorf("decode WireGuard key: %w", err)
}
if len(decoded) != keySize {
return key, fmt.Errorf("WireGuard key decoded length is %d, want %d", len(decoded), keySize)
}
copy(key[:], decoded)
return key, nil
}