使用GO语言验证证书的有效期

package main import ( "crypto/x509" "encoding/pem" "fmt" "io/ioutil" "time" ) func main() { certPEM, err := ioutil.ReadFile("path/to/certificate.pem") if err != nil { fmt.Println("Error reading certificate file:", err) return } block, _ := pem.Decode(certPEM) if block == nil { fmt.Println("Failed to parse certificate PEM") return } cert, err := x509.ParseCertificate(block.Bytes) if err != nil { fmt.Println("Error parsing certificate:", err) return } fmt.Println("Certificate Expiry Date:", cert.NotAfter) now := time.Now() if now.Before(cert.NotBefore) { fmt.Println("Certificate is not yet valid") } else if now.After(cert.NotAfter) { fmt.Println("Certificate has expired") } else { fmt.Println("Certificate is valid") } }
上一篇:iNet Network Scanner Mac 网络扫描工具


下一篇:【二叉树】Leetcode 94. 二叉树的中序遍历【简单】-Java实现中序遍历