Generate a Keygen of 256 bits
Example
package main
import (
"crypto/rand"
"math/big"
"fmt"
"os"
"strconv"
)
const (
keyList string = "abcdefghijklmnopqrstuvwxyzABCDEFHFGHIJKLMNOPQRSTUVWXYZ1234567890"
)
func main() {
size := "256"
strLen, _ := strconv.Atoi(size)
filename := "keygen"
os.Create(filename)
f, _ := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0777)
for key := 1; key <= strLen; key++ {
res, _ := rand.Int(rand.Reader, big.NewInt(64))
keyGen := keyList[res.Int64()]
stringGen := fmt.Sprintf("%c", keyGen)
f.Write([]byte(stringGen))
}
f.Close()
}
Most Helpful This Week
How do you write multi-line strings in Go?
How to create Map using the make function in Go?
Regular expression to extract DNS host-name or IP Address from string
How to check if a string contains certain characters in Golang?
Example of Pointers with Struct
Regular Expression to get a string between parentheses in Golang