aboutsummaryrefslogtreecommitdiff
path: root/tools/pubkey.go
blob: 464966434445e15b15a522918961552d5d28b9ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"crypto/x509"
	"encoding/pem"
	"fmt"
	"log"
	"os"
)

func main() {
	keyFile := "key.pem"
	if len(os.Args) > 1 {
		keyFile = os.Args[1]
	}

	keyData, err := os.ReadFile(keyFile)
	if err != nil {
		log.Panicf("failed to read key \"%v\": %v", keyFile, err)
	}

	keyBlock, _ := pem.Decode(keyData)
	if keyBlock == nil {
		log.Panicf("key \"%v\" is empty")
	}

	privateKey, err := x509.ParsePKCS1PrivateKey(keyBlock.Bytes)
	if err != nil {
		log.Panic("failed to read PKCS1 RSA private key: %v", err)
	}

	fmt.Println("N", privateKey.N)
	fmt.Println("E", privateKey.E)
}