| 38 | ) |
| 39 | |
| 40 | func tryParsePrivateKey(key string) (*rsa.PrivateKey, error) { |
| 41 | keyBlock, _ := pem.Decode([]byte(key)) |
| 42 | if keyBlock == nil { |
| 43 | return nil, fmt.Errorf("unsupported key type") |
| 44 | } |
| 45 | |
| 46 | if pkcs8PrivateKey, err := x509.ParsePKCS8PrivateKey(keyBlock.Bytes); err == nil { |
| 47 | if rsaPrivateKey, ok := pkcs8PrivateKey.(*rsa.PrivateKey); !ok { |
| 48 | return nil, fmt.Errorf("unsupported key type") |
| 49 | } else { |
| 50 | return rsaPrivateKey, nil |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return x509.ParsePKCS1PrivateKey(keyBlock.Bytes) |
| 55 | } |
| 56 | |
| 57 | func X509ParseCert(cert string) (*x509.Certificate, error) { |
| 58 | formattedCert := cert |