1

EDIT

I have deleted this file so don't waste your time trying to help me! I had a backup copy so I didn't lose a lot of information. I'm still not sure what caused this to happen but my best guess is that I accidentally entered the wrong password twice in a row. This is extremely unlikely though given how long my password is. Simply baffling.

I'm trying to decrypt a gpg file containing an archived directory (via tar) with my important files. Here's the output when I run my decryption script or run the decrypt line outside of the script

gpg: AES256.CFB encrypted data
gpg: encrypted with 1 passphrase
gpg: decryption failed: Bad session key

This is the message I get on Ubuntu 22.04 LTS (gpg version 2.2.27) no matter where the file is and a live disc containing Manjaro 22.0.4 KDE edition (gpg version 2.2.40). I've never had problems with this until recently but I am newish to gpg so I definitely could be the cause of this. I'm still able to encrypt and decrypt if I try it on a test directory. I've also tried every possible password that I could have accidentally used in my password manager to encrypt the archived directory.

Here is my decryption script:

#!/bin/bash

#Exit the script if any statement returns a non-true return value. Same as `set -e` but more readable. 
set -o errexit
#Disconnect from network first! Use `ifconfig -a` or `nmcli c` (if you use Network Manager) to list network interfaces
sudo ifconfig wlp2s0 down
cd ~/Documents
#Decrypting directory
gpg --decrypt < 'Cleaning Supplies.gpg' > 'Cleaning Supplies'
#Extracting files from archive and deleting encrypted directory
tar xf 'Cleaning Supplies'; rm -f 'Cleaning Supplies.gpg' 
sudo ifconfig wlp2s0 up

And here is my encryption script:

#!/bin/bash

#Exit the script if any statement returns a non-true return value. Same as `set -e` but more readable. 
set -o errexit
#Disconnect from network first! Use `ifconfig -a` or `nmcli c` (if you use Network Manager) to list network interfaces
sudo ifconfig wlp2s0 down
#IMPORTANT: If this is the first time you have run gpg, this will create a trust database for the current user.
#gpg --list-keys
cd ~/Documents
#Archive (tar cf) and compress (a option; xz extension) directory before encrypting it. 
tar caf 'Cleaning Supplies.tar.xz' 'Cleaning Supplies'
#Encrypting a directory using symmetric keys
gpg --symmetric --s2k-mode 3 --s2k-count 65011712 --s2k-digest-algo SHA512 --s2k-cipher-algo AES256 < 'Cleaning Supplies.tar.xz' > 'Cleaning Supplies.gpg'
#Deleting original directory and archived, compressed directory
rm -rf 'Cleaning Supplies' 'Cleaning Supplies.tar.xz'
sudo ifconfig wlp2s0 up 

I referred to gpg: decryption failed: Bad session key and tried to reload the gpg agent with gpgconf --reload gpg-agent but that didn't help. The top answer their suggests that encryption and decryption were done with different versions of gpg. But I'm using Ubuntu 22.04 LTS and the version of gpg in the apt repositories which has been 2.2.27 for quite some time. Certainly it didn't change in the past few weeks since I last encrypted the directory. I also tried running the decryption command with --pinentry-mode loopback inside the script and outside of the script but that didn't help either.

The only other thing I can think of that may have caused problems was messing with the sound card on my computer and my external usb microphone. I referred to https://raspberrypi.stackexchange.com/questions/63072/setup-output-and-input-audio-on-different-cards among many sources and put the following in ~/.asoundrc

pcm.!default {
    type asym
    playback.pcm "plughw:0"
    capture.pcm  "plughw:1"
}

I then sourced this file. Ever since I created this file, whenever I boot up my computer, the first thing I get is the following 4 lines

[    2.448668] blacklist: Problem blacklisting hash (-13)
[    2.448735] blacklist: Problem blacklisting hash (-13)
[    2.448778] blacklist: Problem blacklisting hash (-13)
[    2.448801] blacklist: Problem blacklisting hash (-13)

The only thing different is the leading number in these lines.

I'm really at a loss here. There doesn't seem to be much more online about the issue I'm encountering. Any help is appreciated.

  • I feel your pain. Don't know anything about `gpg` (not really) but try hiding that troublesome file? Copy the `tar` file to another machine where your `gpg` environment is working and try your passwords there? Make sure the caps-lock key isn't on? Sorry, that's all I got for now. Good luck! – shellter Mar 03 '23 at 23:56
  • Do you mean to rename the file to a hidden file? I may try on another machine but I would like it work on my machine eventually. Caps lock is off. Thanks for the suggestions! – Growing My Roots Mar 04 '23 at 02:39
  • Yes, rename or move the file so it doesn't get read into your current environment. Get back to a state where things are working again. Then add one thing at a time until you figure out what is breaking it. OR maybe you'll luck out and get a `gpg` guro to read this quesiton. Good luck. – shellter Mar 04 '23 at 03:33

0 Answers0