Ejemplo n.º 1
0
func main() {

	flag.StringVar(&outputFile, "o", defaultOutputFile, "Output key file. Ex: -a='./mykey.dat'. Default: ./key.dat")
	flag.IntVar(&keySize, "b", defaultKeySize, "Key Size(bits). Ex: -b='256'. Default: 512 bits")

	flag.Parse()

	if err := keygen.GenSymmetricKeyFile(keySize, outputFile, defaultPerm); err != nil {
		fmt.Printf("Generate symmetric key error: %v\n", err)
	} else {
		fmt.Printf("Generate symmetric key successfully.\n")
	}
}
Ejemplo n.º 2
0
func ExampleGenSymmetricKeyFile() {
	var err error
	size := 512 // Key size = 256 bits.

	u, _ := user.Current()
	username := u.Username
	keyFile := fmt.Sprintf("/home/%v/my.key", username) // make absolute key path for current user.

	p, err := pathhelper.GetAbsPath(keyFile)
	if err != nil {
		fmt.Printf("GetAbsPath(%v) error: %v\n", keyFile, err)
	}

	fmt.Fprintf(os.Stderr, "Key file: %v\n", p)

	if err = keygen.GenSymmetricKeyFile(size, p, 0660); err != nil {
		fmt.Printf("GenSymmetricKeyFile(%v) error: %v\n", size, err)
	}

	// Output:
}