Exemple #1
0
func doKeyInfo() {
	b, err := ioutil.ReadFile(*kiFilename)
	log.Fatale(err, "cannot read keyfile")

	var sk [64]byte
	isPrivate, err := spki.LoadKeyFile(bytes.NewReader(b), &sk)
	log.Fatale(err, "cannot decode keyfile")

	if isPrivate {
		fmt.Fprintf(os.Stderr, ";; Ed25519 Private Key\n")
	} else {
		fmt.Fprintf(os.Stderr, ";; Ed25519 Public Key\n")
	}
	fmt.Fprintf(os.Stderr, ";; Fingerprint: %v\n", hexFormat(sk[32:64]))
	fmt.Fprintf(os.Stderr, ";; Fingerprint (b32): %v\n", spki.EncodeB32(sk[32:64]))
	fmt.Fprintf(os.Stderr, "%s", prefix(randomart.Generate(sk[32:64], " Ed25519").String()))

	var cpk [32]byte
	var edpub [32]byte
	copy(edpub[:], sk[32:64])
	if !extra25519.PublicKeyToCurve25519(&cpk, &edpub) {
		log.Fatal("Cannot derive Curve25519 public key.")
	}

	fmt.Fprintf(os.Stderr, ";; Curve25519 Fingerprint: %v\n", hexFormat(cpk[:]))
	fmt.Fprintf(os.Stderr, ";; Curve25519 Fingerprint (b32): %v\n", spki.EncodeB32(cpk[:]))
}
Exemple #2
0
func doGenerateKeyEd25519() {
	_, sk, err := ed25519.GenerateKey(rand.Reader)
	log.Fatale(err, "cannot generate key")

	s, err := sx.SXCanonical.String(spki.FormEd25519PrivateKey(sk))
	log.Fatale(err, "cannot serialize key")

	fmt.Fprintf(os.Stderr, ";; Fingerprint: %v\n;;\n", hexFormat(sk[32:64]))

	fmt.Fprintf(os.Stderr, "%s", prefix(randomart.Generate(sk[32:64], " Ed25519").String()))

	w, err := armor.Encode(os.Stdout, "SPKI PRIVATE KEY", map[string]string{
		"Version": "Davka",
	})
	log.Fatale(err)

	defer w.Close()
	w.Write([]byte(s))
}