GetPublicKeyArmorBytes 读取GPG证书信息
(entity *openpgp.Entity)
| 178 | |
| 179 | // GetPublicKeyArmorBytes 读取GPG证书信息 |
| 180 | func GetPublicKeyArmorBytes(entity *openpgp.Entity) ([]byte, error) { |
| 181 | pathname := path.Join("/tmp/" + uuid.NewV4().String() + ".key") |
| 182 | fp, err := os.Create(pathname) |
| 183 | if err != nil { |
| 184 | return nil, err |
| 185 | } |
| 186 | defer os.Remove(pathname) |
| 187 | |
| 188 | w, err := armor.Encode(fp, openpgp.PublicKeyType, nil) |
| 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } |
| 192 | err = entity.Serialize(w) |
| 193 | if err != nil { |
| 194 | return nil, err |
| 195 | } |
| 196 | _ = w.Close() |
| 197 | _ = fp.Close() |
| 198 | |
| 199 | data, err := ioutil.ReadFile(pathname) |
| 200 | if err != nil { |
| 201 | return nil, err |
| 202 | } |
| 203 | return data, nil |
| 204 | } |
| 205 | |
| 206 | // GetArmorPublicKey 从文件读取GPG证书公钥信息 |
| 207 | func GetArmorPublicKey(gpgKeyFile string, passphrase []byte) (*DigitalSignPEM, error) { |
no test coverage detected