GO語言"crypto/tls"包中"LoadX509KeyPair"函數的用法及代碼示例。
用法:
func LoadX509KeyPair(certFile, keyFile string)(Certificate, error)
LoadX509KeyPair 從一對文件中讀取並解析公鑰/私鑰對。這些文件必須包含 PEM 編碼數據。證書文件可以包含在葉證書之後的中間證書以形成證書鏈。成功返回時,Certificate.Leaf 將為 nil,因為不保留已解析的證書形式。
例子:
package main
import (
"crypto/tls"
"log"
)
func main() {
cert, err := tls.LoadX509KeyPair("testdata/example-cert.pem", "testdata/example-key.pem")
if err != nil {
log.Fatal(err)
}
cfg := &tls.Config{Certificates: []tls.Certificate{cert}}
listener, err := tls.Listen("tcp", ":2000", cfg)
if err != nil {
log.Fatal(err)
}
_ = listener
}
相關用法
- GO LoadLocation用法及代碼示例
- GO Logger.Output用法及代碼示例
- GO Log10用法及代碼示例
- GO Log用法及代碼示例
- GO Logger用法及代碼示例
- GO LookPath用法及代碼示例
- GO LookupEnv用法及代碼示例
- GO Location用法及代碼示例
- GO Log2用法及代碼示例
- GO LeadingZeros32用法及代碼示例
- GO LastIndex用法及代碼示例
- GO LeadingZeros8用法及代碼示例
- GO LeadingZeros16用法及代碼示例
- GO ListenAndServe用法及代碼示例
- GO Listener用法及代碼示例
- GO LastIndexAny用法及代碼示例
- GO Len8用法及代碼示例
- GO ListenAndServeTLS用法及代碼示例
- GO LastIndexFunc用法及代碼示例
- GO Len64用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 LoadX509KeyPair。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。