aboutsummaryrefslogtreecommitdiff
path: root/tools/pubkey.go
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pubkey.go')
-rw-r--r--tools/pubkey.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/pubkey.go b/tools/pubkey.go
new file mode 100644
index 0000000..4649664
--- /dev/null
+++ b/tools/pubkey.go
@@ -0,0 +1,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)
+}