Example #1
0
//
// create a keyring, then add a key to it, and list the result.
//
func main() {

	keyRingName := "jen's keyring"

	keyring, err := keyutils.NewKeyRing(keyRingName, keyutils.KEY_SPEC_USER_KEYRING)

	if err != nil {
		log.Fatal("Error adding keyring:", err)
	}

	id, err := keyutils.AddKey(keyutils.USER, "ssh key", "ssh key secret data", keyring)

	if err != nil || id == 0 {
		log.Fatal("Error adding key:", err)
	}

	id, err = keyutils.AddKey(keyutils.USER, "password for Github", "my github password", keyring)

	if err != nil || id == 0 {
		log.Fatal("Error adding key:", err)
	}

	if keys, err := keyutils.ListKeysInKeyRing(keyring); err != nil {
		log.Fatal(err)
	} else {
		log.Printf("%s (%d keys):", keyRingName, len(keys))
		for id, key := range keys {
			log.Printf("-- #%d: %s (uid=%d, gid=%d)", id, key.Description, key.Uid, key.Gid)
		}
	}

}
Example #2
0
func main() {
	id, err := keyutils.AddKey(keyutils.USER, "test123", "hello", keyutils.KEY_SPEC_USER_KEYRING)

	if err != nil {
		log.Fatal("Error adding key:", err)
	}
	log.Println("Added key test123 with serial:", id)
	val, err := keyutils.ReadKey(id)

	if err != nil {
		log.Fatal("Error reading key:", err)
	}

	log.Println("Read:", val)
}