0

Thanks for pointing out the mistake @Topaco. Now it works like a charm.

Question: If, within one table, I have more than one column which need to be encrypted, ['Salary', 'SocialNumber'] of type integer and string respectively, like:

data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Salary': [50000, 70000, 90000],
        'SocialNumber': ['AX12', 'ER56', 'ES11']}

does the encrypting stays the same (should both be of type str?):

df['Salary'] = df['Salary'].apply(lambda x: f.encrypt(str(x).encode()).decode())
df['SocialNumber'] = df['SocialNumber'].apply(lambda x: f.encrypt(str(x).encode()).decode())

but only the decrpyting should consider the types (int and str?):

df_new['Salary'] = df_new['Salary'].apply(lambda x: int(v.decrypt(x.encode()).decode()))
df_new['SocialNumber'] = df_new['SocialNumber'].apply(lambda x: str(v.decrypt(x.encode()).decode()))

I am following answer as in https://stackoverflow.com/questions/75777010/invalidtoken-by-decrypting-column-in-table-using-python/75782711#75782711

Susy84
  • 104
  • 6
  • 1
    Your code works on my machine. But since `SocialNumber` is already a string, the `str()` can actually be omitted, i.e. for encryption: `apply(lambda x: f.encrypt(x.encode()).decode())` and for decryption: `apply(lambda x: v.decrypt(x.encode()).decode())`. – Topaco Mar 19 '23 at 16:28

0 Answers0