Help: Encrypting and Decrypting ASCII armor PGP Messages with golang.org/x/crypto/openpgp

166 views
Skip to first unread message

Samuel Lorch

unread,
Aug 18, 2020, 1:00:50 PM8/18/20
to golang-nuts

Hi,


i have been trying to decrypt and encrypt ASCII armor PGP Messages that i receive and send to a API.


I Wrote a function for decrypting messages and another one for encrypting messages. The Decrypting function Works and i can decrypt the API's messages. But My encrypt function Seems to be broken as Neither the API or my decrypt function can decrypt the Messages encrypted by my encrypt function.


Decrypting the encrypted messages from my encrypt function always result in the following error:

"Error reading message: openpgp: unsupported feature: unknown SymmetricallyEncrypted version"


I have uploaded a example to the Go Play Ground : https://play.golang.org/p/JhhZ4xWWYvn


Any help is Appreciated.

Diego Medina

unread,
Oct 10, 2020, 6:31:48 PM10/10/20
to golang-nuts
There is only a small change I had to do to get it to encrypt and decrypt:


inside your encryptMessage() func, change:

_, err = encryptorWriter.Write([]byte(message))
//messageReader := bytes.NewReader([]byte(message))
//_, err = io.Copy(encoderWriter, messageReader)

using the Write() method vs io.Copy works

Also, you don't need the chunk about the private key in the encrypt function

Updated playground link


Thanks

Diego
Reply all
Reply to author
Forward
0 new messages