如何从tls cert和key创建PGP密钥并使用PGP私钥解密golang中的PGP消息?

时间:2016-11-08 22:26:03

标签: go

以以下逻辑开始,

(基于:RSA关键部分对于TLS和PGP是常见的)

tlsCert, err := tls.LoadX509KeyPair(certFilePath, keyFilePath)
if err != nil {
    return
}
certx509, _ := ioutil.ReadFile(certFilePath)

block, _ := pem.Decode([]byte(certx509))
certTest, err := x509.ParseCertificate(block.Bytes)
if err != nil {
    return
}

privateKeyTest := tlsCert.PrivateKey

config = &packet.Config{}
config.DefaultCompressionAlgo = 1
config.DefaultCipher = 9
config.DefaultHash = 3
entity, _ = openpgp.NewEntity("", "", "", config)
entity.PrimaryKey.PublicKey = (certTest.PublicKey).(*rsa.PublicKey)
entity.PrivateKey.PrivateKey = privateKeyTest.(*rsa.PrivateKey)

entitylist := make(openpgp.EntityList, 1)
entitylist[0] = entity

md, err := openpgp.ReadMessage(encryptedmessagebytes, entitylist , nil, config)

openpgp.ReadMessage返回以下错误

openpgp:无效数据:标记字节没有MSB集

我认为在创建实体时我错过了一些东西。你能帮帮我吗?

0 个答案:

没有答案