G
G
genek_orlov2018-11-25 14:19:03
Python
genek_orlov, 2018-11-25 14:19:03

RSA encryption keys. I write the key to the database and convert it to the string type, and how to encrypt it after that?

(pubkey, privkey) = rsa.newkeys(512)
cur.execute("INSERT INTO persons (domain, key ) VALUES (%s,%s)", (domain, str(pubkey)))
conn.commit()

As you can see in the screenshot, I create encryption keys and enter them into the database, how can I use this key for encryption after that? I need to read it from the database and encrypt information on it, but in the database it is of type string, and the key itself, as I understand it, is byte

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2018-11-25
@Zarom

After reading the key from the database, before using it, convert the string to bytes
pubkey.encode()
But before saving to the database pubkey.decode() instead of casting to a string - it will be more correct.
It is assumed that your database is utf8-coloured

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question