func ExampleParsePKIXPublicKey() {
raw, err := ioutil.ReadFile("/Path/To/DER/Encoded/Certificate")
if err != nil {
panic("failed to read certificate" + err.Error())
}
pub, err := x509.ParsePKIXPublicKey(raw)
if err != nil {
panic("failed to parse DER encoded public key: " + err.Error())
}
switch pub := pub.(type) {
case *rsa.PublicKey:
fmt.Println("Pub is of type RSA:", pub)
case *dsa.PublicKey:
fmt.Println("Pub is of type DSA:", pub)
case *ecdsa.PublicKey:
fmt.Println("Pub is of type ECDSA:", pub)
default:
panic("unknown type fo public key")
}
}
panic: failed to parse DER encoded public key: asn1: structure error: tags don't match (6 vs {class:2 tag:0 length:3 isCompound:true}) {optional:false explicit:false application:f
alse defaultValue:<nil> tag:<nil> stringType:0 timeType:0 set:false omitEmpty:false} ObjectIdentifier @2