Generate a self-signed certificate for Golang

Use OpenSSL generate a self-signed certificate for Golang. In this code snippet
I created a certificate with validity of 15 years.

openssl genrsa -out server.key 2048
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 5475

Once you create the certificate and key you can use it in your Golang HTTP like this

log.Fatal(http.ListenAndServeTLS(":"+port, configuration.HTTP.ServerCert, configuration.HTTP.ServerKey, router)) // Start HTTP Server

Leave a Reply