Skip to content

How to decode PKCS#12 file into a tls.Certificate (for use in tls.Config) #55

Closed Answered by AGWA
ykunya asked this question in Q&A
Discussion options

You must be logged in to vote

Here's how to decode a PKCS#12 file into a tls.Certificate:

key, leafCert, chainCerts, err := pkcs12.DecodeChain(rawDecodedCert, certPassword)
if err != nil {
	// handle err
}

raw := [][]byte{leafCert.Raw}
for _, chainCert := range chainCerts {
	raw = append(raw, chainCert.Raw)
}

tlsCert := tls.Certificate{
	Certificate: raw,
	PrivateKey: key,
	Leaf: leafCert,
}

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@ykunya
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by AGWA
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants