RSA has several key formats. Is there a way to extract a PKCS 1 private key from a PGP key in golang? Something lik this (it does not work):
var e *openpgp.Entity
e, err := openpgp.NewEntity("test11", "test", "test@test.com", nil)
if err != nil {
fmt.Println(err)
return
}
key, ok := e.PrivateKey.PrivateKey.(rsa.PrivateKey)
if !ok {
// Here is the problem in this solution
fmt.Printf("Assertation failed")
}
pkcs1PrivateKey := x509.MarshalPKCS1PrivateKey(&key)
privkey_pem := pem.EncodeToMemory(
&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: pkcs1PrivateKey,
},
)
fmt.Printf(string(privkey_pem))