I've been using rsa python library to encrypt and decrypt data, all is working fine. However when I save the encrypted data to a CSV file using pandas and if try to decrypt the saved data value by extracting it from the CVS file, then it no longer works
Below is my python code
import rsa
import pandas as pd
key = int(input("enter an interger key value : ")) #512
paasword = input("input pass : ")
publicKey, privateKey = rsa.newkeys(key)
encpass = rsa.encrypt(paasword.encode(),publicKey)
print("\noriginal string: ", paasword)
print("\nencrypted string: ", encpass)
# Save to New CSV file
data={'Name':['Jhon'], 'Password':[encpass], } #new dict
df = pd.DataFrame(data) # create new pandas DataFrame
df.to_csv('my_data.csv', index=False) # write a new csv file
# Extract form CSV file
df = pd.read_csv("my_data.csv",index_col = 0) #using 0th column (Name) as index
find_password = df['Password']['Jhon'] #column id , index of that row;
print(find_password)
decpass = rsa.decrypt(find_password, privateKey).decode()
print("\ndecrypted string: ", decMessage)
> enter an integer key value: 512
> input pass: abhijeetbyte123
> original string: abhijeetbyte123
> encrypted string: b',.\x89\xb8&"\xdc|\x97.................................
> error : TypeError: cannot convert 'str' object to bytes
What should I do to fix this error