HAOJX

如何解析caCert,caPrikey

字数统计: 98阅读时长: 1 min
2022/01/05 Share
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const CAFILE="./test/certs/ca.crt"
const CAKEY="./test/certs/ca.key"

func parseK8sCA(cafile,cakey string) (*x509.Certificate,*rsa.PrivateKey) {
//parse ca.crt and ca.key
caFile,err:= ioutil.ReadFile(CAFILE)
if err != nil {
log.Fatal(err)
}
caBlock,_:= pem.Decode(caFile)

caCert,err := x509.ParseCertificate(caBlock.Bytes)
if err != nil {
log.Fatal(err)
}

//parse CAKEY
keyFile,err:= ioutil.ReadFile(CAKEY)
if err != nil {
log.Fatal(err)
}
keyBlock,_:=pem.Decode(keyFile)
caPriKey,err:= x509.ParsePKCS1PrivateKey(keyBlock.Bytes)
if err != nil {
log.Fatal(err)
}

return caCert,caPriKey
}
CATALOG