5 Star 1 Fork 0

hilaoyu / go-basic-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cert.go 555 Bytes
一键复制 编辑 原始数据 按行查看 历史
hilaoyu 提交于 2023-08-15 16:15 . update utilHttp cert
package utilSsl
import (
"encoding/pem"
"os"
)
func ParseCertPemFile(path string) (pkey []byte, cert []byte) {
b, _ := os.ReadFile(path)
return ParseCertPemContent(b)
}
func ParseCertPemContent(content []byte) (pkey []byte, cert []byte) {
var pemBlocks []*pem.Block
var v *pem.Block
pem.Decode(content)
for {
v, content = pem.Decode(content)
if v == nil {
break
}
if v.Type == "PRIVATE KEY" {
pkey = pem.EncodeToMemory(v)
} else {
pemBlocks = append(pemBlocks, v)
}
}
cert = pem.EncodeToMemory(pemBlocks[0])
return
}
Go
1
https://gitee.com/hilaoyu/go-basic-utils.git
git@gitee.com:hilaoyu/go-basic-utils.git
hilaoyu
go-basic-utils
go-basic-utils
5f3621a25f8a

搜索帮助

53164aa7 5694891 3bd8fe86 5694891