1 year ago
#358798
Sam Hughes
TypeError: can only concatenate str (not "bytes") to str - decrypting from pandas
I'm trying to decrypt my encrypted data stored in a text file from my DropBox bucket. When I create a pandas dataframe of the txt data and match it up with my user input, I exclusively pick the row that matches. Using this data I run it through my decryption (AES_CBC).
When I run I get the error: "TypeError: can only concatenate str (not "bytes") to str
"
The error appears from my padding function (p4 = padded_text(df1)
)
I'm not sure if this is an encoding issue, or if the fact I'm using .get()
as my user input and because that's a string it isn't working. Any help would be greatly appreciated.
def login():
import sqlite3
import os.path
def decoder():
from Crypto.Cipher import AES
import hashlib
from secrets import token_bytes
cursor.execute(
'''
Select enc_key FROM Login where ID = (?);
''',
(L_ID_entry.get(), ))
row = cursor.fetchone()
if row is not None:
keys = row[0]
import pyDes
#design padding function for encryption
def padded_text(data_in):
while len(data_in)% 16 != 0:
data_in = data_in + b"0"
return data_in
#calling stored key from main file and reverting back to bytes
key_original = bytes.fromhex(keys)
mode = AES.MODE_CBC
#model
cipher = AES.new(key_original, mode, IV3)
#padding data
p4 = padded_text(df1)
p5 = padded_text(df2)
p6 = padded_text(df3)
#decrypting data
d_fname = cipher.decrypt(p4)
d_sname = cipher.decrypt(p5)
d_email = cipher.decrypt(p6)
#connecting to db
try:
conn = sqlite3.connect('login_details.db')
cursor = conn.cursor()
print("Connected to SQLite")
except sqlite3.Error as error:
print("Failure, error: ", error)
finally:
#downloading txt from dropbox and converting to dataframe to operate on
import New_user
_, res = client.files_download("/user_details/enc_logins.txt")
with io.BytesIO(res.content) as csvfile:
df = pd.read_csv(csvfile, sep=';', names=['ID', 'Fname', 'Sname', 'Email'])
newdf = df.loc[df['ID'] == L_ID_entry.get()]
print(newdf)
df1 = newdf['Fname']
df2 = newdf['Sname']
df3 = newdf['Email']
csvfile.close()
decoder()
python
pandas
csv
aes
cbc-mode
0 Answers
Your Answer