Having issues Decrypting Binary File #203
Unanswered
andrewlaguna824
asked this question in
Q&A
Replies: 2 comments 3 replies
-
Hi, there's no helper function to decrypt unarmored messages. But you can write your own using the crypto package. The code would look something like that: func DecryptMessageUnarmored(
privateKey string, passphrase []byte, ciphertext []byte,
) (plaintext string, err error) {
var privateKeyObj, unlockedKeyObj *crypto.Key
var privateKeyRing *crypto.KeyRing
var pgpMessage *crypto.PGPMessage
var message *crypto.PlainMessage
if privateKeyObj, err = crypto.NewKeyFromArmored(privateKey); err != nil {
return "", errors.Wrap(err, "gopenpgp: unable to unarmor private key")
}
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
return "", errors.Wrap(err, "gopenpgp: unable to unlock private key")
}
defer unlockedKeyObj.ClearPrivateParams()
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
return "", errors.Wrap(err, "gopenpgp: unable to create new keyring")
}
if pgpMessage, err = crypto.NewPGPMessage(ciphertext); err != nil {
return "", errors.Wrap(err, "gopenpgp: unable to unarmor ciphertext")
}
if message, err = privateKeyRing.Decrypt(pgpMessage, nil, 0); err != nil {
return "", errors.Wrap(err, "gopenpgp: unable to decrypt message")
}
return message.GetString(), nil
} This is basically the same helper, but the message object is built with |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I have an encrypted, signed file that is in binary format. My goal is to decrypt the message and verify its signature.
Currently, I am using
helper.DecryptVerifyMessageArmored(senderPublicKey, receiverPrivateKey, nil, cipherText)
.The cipher text is in binary format (e.g.
��
Կ�ú�K斖��1wPb"�jItc~��` ... ).When calling the above decryption function, I receive the error:
After some digging around online, it seems that perhaps the issue is that the cipher text is unarmored (link).
If this is the issue, is there a way I need to armor the cipher text before passing to the decrypt function? I do not have the ability to change the incoming file -- it is being received from a third party.
As a note, I can successfully decrypt and verify the message using the
gpg
command line util.Beta Was this translation helpful? Give feedback.
All reactions