企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# package pem `import "encoding/pem"` pem包实现了PEM数据编码(源自保密增强邮件协议)。目前PEM编码主要用于TLS密钥和证书。参见[RFC 1421](http://tools.ietf.org/html/rfc1421) ## Index * [type Block](#Block) * [func Decode(data []byte) (p \*Block, rest []byte)](#Decode) * [func Encode(out io.Writer, b \*Block) error](#Encode) * [func EncodeToMemory(b \*Block) []byte](#EncodeToMemory) ## type [Block](https://github.com/golang/go/blob/master/src/encoding/pem/pem.go#L25 "View Source") ``` type Block struct { Type string // 得自前言的类型(如"RSA PRIVATE KEY") Headers map[string]string // 可选的头项 Bytes []byte // 内容解码后的数据,一般是DER编码的ASN.1结构 } ``` Block代表PEM编码的结构。编码格式如下: ``` -----BEGIN Type----- Headers base64-encoded Bytes -----END Type----- ``` 其中Headers是可为空的多行键值对。 ### func [Decode](https://github.com/golang/go/blob/master/src/encoding/pem/pem.go#L76 "View Source") ``` func Decode(data []byte) (p *Block, rest []byte) ``` Decode函数会从输入里查找到下一个PEM格式的块(证书、私钥等)。它返回解码得到的Block和剩余未解码的数据。如果未发现PEM数据,返回(nil, data)。 ## func [Encode](https://github.com/golang/go/blob/master/src/encoding/pem/pem.go#L218 "View Source") ``` func Encode(out io.Writer, b *Block) error ``` ## func [EncodeToMemory](https://github.com/golang/go/blob/master/src/encoding/pem/pem.go#L273 "View Source") ``` func EncodeToMemory(b *Block) []byte ```