0

I used this code to encrypt the column of conversationID which is a column in a table, the problem is that it encrypts all the values even with same ID. I am looking for a solution that could encrypt only the different values , I mean , for the same conversationID it should returns the same encrypt value, it should not be different. Here is the code used:

import cryptography
from cryptography.fernet import Fernet
key = Fernet.generate_key()
conversation_encrypt=ConversationID.encode()
f = Fernet(key)
for m in TRF:
    ConversationID = str(m.ConversationID)
    conversation_encrypt=ConversationID.encode()
    encrypted_message = f.encrypt(conversation_encrypt)
    print(encrypted_message)
Chaa MH
  • 73
  • 7
  • What's the purpose of this encryption? – bereal Jul 07 '21 at 08:24
  • To keep the column values anonymous – Chaa MH Jul 07 '21 at 08:25
  • Fernet was on purpose designed like this to achieve semantic security. You could try another method, e.g. aliasing the internal values to some public random values via a new table. – bereal Jul 07 '21 at 08:29
  • I have trouble understanding the question. Are you secretly looking for [hashing](https://docs.python.org/3/library/hashlib.html)? Do you need to decrypt the IDs or is it enough to have the encrypted version, where the same input value always gets the same "encrypted" value? More background information would help. – André Jul 07 '21 at 08:32
  • I just would like to encrypt them without the need of decrypt. The code is working but the problem is that it is encrypting ALL the values even with the same ID I have different value of encrypting ( I mean for a the row 1 I have value X10 and for the row 10 Ihave the same value X10 if I do this method it returns for example F123 for row1 and WD456 for row 10) which is false because they are different it must return the same value since the rows have the same values ( it must return F123 nad F123) for example – Chaa MH Jul 07 '21 at 09:16
  • I will try with the hashing – Chaa MH Jul 07 '21 at 09:19

0 Answers0