时间:2023-07-24 15:24:01 | 来源:网站运营
时间:2023-07-24 15:24:01 来源:网站运营
如何在私有网站使用并创建https的证书:证书是如何生成的及ssl加密原理是什么样的?openssl req -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr
证书签名请求输出两个文件。一个是[organization_domain_name].crt,另一个是intermediate.crt(如果您的中间 CA 是 GoDaddy,则称为gd-bundle-g2-.crt)# Generate CA private key openssl genrsa -des3 -passout pass:demo -out ca.key 2048# Generate CSR openssl req -new -key ca.key -out ca.csr
系统将提示您输入密码,我建议不要跳过并确保安全。Generating RSA private key, 2048 bit long modulus.................................................................+++.....................................+++e is 65537 (0x10001)Enter pass phrase for ca.key:Verifying - Enter pass phrase for ca.key:
然后我们生成一个根证书:openssl req -x509 -new -nodes -key ca.key -sha256 -days 1825 -out ca.pem# 或者使用下面 生成crt文件# Generate Self Signed certificate(CA 根证书) openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt Enter pass phrase for ca.key:You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [AU]:CNState or Province Name (full name) [Some-State]:GuangdongLocality Name (eg, city) []:ShenZhengOrganization Name (eg, company) [Internet Widgits Pty Ltd]: demoOrganizational Unit Name (eg, section) []: demoCommon Name (e.g. server FQDN or YOUR name) []: demo1Email Address []:1062186165@qq.com
您现在应该有两个文件:ca.key(私钥)和 ca.pem(根证书)还有一个 ca.csr。# private key openssl genrsa -aes256 -passout pass:111111 -out server.key 2048# generate csr openssl req -new -key server.key -out server.csr
使用 CA 证书及CA密钥 对请求签发证书进行签发,生成 x509证书# generate certificate openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key # 或者使用openssl x509 -req -days 3650 -in server.csr -CA ca.pem -CAkey ca.key -passin pass:111111 -CAcreateserial -out server.crt
客户端用户证书:openssl genrsa -des3 -out client.key 1024 openssl req -new -key client.key -out client.csr openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key
生成pem格式证书:cat client.crt client.key> client.pemcat server.crt server.key > server.pem
* 客户端证书包含 client.pem server.key server.csr server.crtopenssl genrsa -out private.key 2048
然后我们创建一个CSR:openssl req -new -key private.key -out cert.csr
您将得到与上述相同的所有步骤,而且您的输出证书的内容并不重要。openssl x509 -req -in cert.csr /-CA ca.pem -CAkey ca.key -CAcreateserial /-out server.crt -days 825 -sha256 /-extfile server.ext
配置文件 (server.ext) 包含以下内容:subjectKeyIdentifier = hashbasicConstraints = critical, CA:truekeyUsage = critical, digitalSignature, nonRepudiation, keyEncipherment, keyCertSignsubjectAltName = @alt_names[alt_names]# 需要添加https的域名DNS.1 = www.baidu.com
我现在有三个文件:private.key(私钥)、server.csr(证书签名请求)和 server.crt(签名证书)。import ( "fmt" "net/http")func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi, This is an example of https service in golang!")}func main() { http.HandleFunc("/", handler) err := http.ListenAndServeTLS(":443", "server.crt", "private.key", nil) if err != nil { panic(err) }}
访问https://localhost, 此时访问本地localhost因为不信任的问题访问不通,需要在mac上面信任这个证书才行。关键词:创建,证书,使用,私有