Example #1
0
func fingerprint(keyfile string, keytype string) {
	var err error

	if keyfile == "" {
		defkey := defaultKey(keytype)
		defkey += ".pub"
		prompt := fmt.Sprintf("Enter file in which the key is (%s): ", defkey)
		keyfile, err = ReadPrompt(prompt)
		checkErr(err)
		if keyfile == "" {
			keyfile = defkey
		}
	}
	pub, err := sshkey.LoadPublicKeyFile(keyfile, true)
	checkErr(err)

	fpr, err := sshkey.FingerprintPretty(pub, 0)
	checkErr(err)

	comment := pub.Comment
	if comment == "" {
		comment = keyfile
	}

	fmt.Printf("%d %s %s (%s)\n", pub.Size(), fpr, comment, strings.ToUpper(keytype))
	os.Exit(0)
}
Example #2
0
// Generate a random box key, encrypt the key to the RSA public key,
// package the box appropriately, and write it out to a file.
func encrypt(in, out, keyfile, signkey string, local, armour bool) (err error) {
	pub, err := sshkey.LoadPublicKeyFile(keyfile, local)
	if err != nil {
		fmt.Printf("[!] failed to load the public key:\n\t%s\n",
			err.Error())
		return
	}
	switch pub.Type {
	case sshkey.KEY_RSA:
		err = encryptRSA(in, out, pub.Key.(*rsa.PublicKey), signkey,
			local, armour)
	case sshkey.KEY_ECDSA:
		err = encryptECDSA(in, out, pub.Key.(*ecdsa.PublicKey), signkey,
			local, armour)
	default:
		err = sshkey.ErrInvalidPrivateKey
		fmt.Println("[!]", err.Error())
	}
	return
}