MCPcopy
hub / github.com/SpecterOps/BloodHound / tryParsePrivateKey

Function tryParsePrivateKey

packages/go/crypto/tls.go:40–55  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

38)
39
40func 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
57func X509ParseCert(cert string) (*x509.Certificate, error) {
58 formattedCert := cert

Callers 1

X509ParsePairFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected