Пример #1
0
func ExampleParse() {
	key, err := xmlkey.Parse(keyXML)
	if err != nil {
		log.Fatal(err)
	}

	if err := key.Validate(); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Exponent: %d", key.PublicKey.E)

	// Output: Exponent: 65537
}
Пример #2
0
func ExampleParse_base64() {
	b64 := make([]byte, base64.StdEncoding.EncodedLen(len(keyXML)))
	base64.StdEncoding.Encode(b64, keyXML)
	key, err := xmlkey.Parse(b64)
	if err != nil {
		log.Fatal(err)
	}

	if err := key.Validate(); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Exponent: %d", key.PublicKey.E)

	// Output: Exponent: 65537
}
Пример #3
0
func main() {
	var in, out string
	flag.StringVar(&in, "in", "STDIN", "The file containing the XML key to parse")
	flag.StringVar(&out, "out", "STDOUT", "The file into which the PEM-encoded key should be written")
	flag.Parse()

	bs, err := ioutil.ReadAll(infile(in))
	if err != nil {
		log.Fatal(err)
	}

	key, err := xmlkey.Parse(bs)
	if err != nil {
		log.Fatal(err)
	}

	err = pem.Encode(outfile(out), &pem.Block{
		Bytes: x509.MarshalPKCS1PrivateKey(key),
		Type:  "RSA PRIVATE KEY",
	})
	if err != nil {
		log.Fatal(err)
	}
}