Created
January 19, 2017 22:06
-
-
Save zuf/222e84597641ff8c1885777d8302aa05 to your computer and use it in GitHub Desktop.
CLI tool which generates random strings (passwords) encoded with base58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import "flag" | |
import "crypto/rand" | |
import "math/big" | |
import "github.com/tv42/base58" | |
func secure_random(n int) []byte{ | |
b := make([]byte, n) | |
_, err := rand.Read(b) | |
if err != nil { | |
fmt.Println("error:", err) | |
panic(fmt.Sprintf("Can't generate rangom bytes:", err)) | |
} | |
return b | |
} | |
func main() { | |
n := flag.Int("n", 16, "random bytes per string") | |
c := flag.Int("c", 1, "generate given number of random strings") | |
flag.Parse() | |
var x big.Int | |
for i := 0; i < *c; i++ { | |
buf := base58.EncodeBig(nil, x.SetBytes(secure_random(*n))) | |
fmt.Printf("%s\n", buf) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment