简体   繁体   中英

Golang: verify cert was signed using private key

I'm porting an app from php to go and can't figure out how to verify a SSL cert was signed by our private key for a given server.

In php its simply: openssl_x509_check_private_key($cert, $pkey)

I can verify start/end dates and validity for a host, but can't see a way to do this.

The docs for openssl_x509_check_private_key don't actually say what the arguments are. I'm going to assume that they're either filenames for PEM encoded data, or PEM encoded data (strings) directly.

In that case you can simply call tls.LoadX509KeyPair or tls.X509KeyPair, which will check that the certificate and key match.

Check the source for tls.X509KeyPair if you are interested in the low-level API that performs the actual check (search for x509.ParseCertificate).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM