#issue with the gopenpgp library

4 messages · Page 1 of 1 (latest)

silent vine
#

im not really sure where else to check but basically when i generate a pgp key via the gpg command, then encrypt a message with the EncryptMessageArmored function and the public key of the previously mentioned keys i generated, it throws an error when i try to decode it:

gopenpgp: unable to unlock key: gopenpgp: key is not locked``` if i dont have a secret key on the keys, and if i do it throws the following error when trying to decrypt:
```gopenpgp: error in reading message: gopenpgp: incorrect key```


my encryption function:
```go

func EncryptMsg(msg, publicKey string) string {
    encrypted, err := helper.EncryptMessageArmored(publicKey, msg)
    if err != nil {
        log.Fatal("failed to encrypt message: " + err.Error())
    }
    return encrypted

}

and the decryption function:

func DecryptMsg(msg, privKey string) []byte {
    fmt.Printf("msg: %s\n", msg)
    decrypted, err := helper.DecryptMessageArmored(privKey, []byte(""), msg)
    if err != nil {
        log.Fatal("failed to decrypt message: " + err.Error())
    }
    return []byte(decrypted)
}

it doesn't matter if i make the passkey a nil type or an empty byte slice, still the same issue.

Any help would be appreciated

wise gulch
#

Passphrase being []byte("") means that there is a password because the passphrase is non nil. If the passphrase is nil; no need to decrypt the private key with the passphrase.

TL;DR your previous code told gopenpgp to decrypt the private key with the passphrase "". It kept trying to do so and failing.

silent vine
#

ty