views:

37

answers:

1

Hi,

I want to encrypt a string using RSA algorithm and then store that string into postgres database using SQLAlchemy in python. Then Retrieve the encrypted string and decrypt it using the same key. My problem is that the value gets stored in the database is not same as the actual encrypted string. The datatype of column which is storing the encrypted value is bytea. I am using pycrypto library. Do I need to change the data in a particular format before inserting it to database table?

Any suggestions please.

Thanks, Tara Singh

A: 

By "same key" you mean "the other key", right? RSA gives you a keypair, if you encrypt with one you decrypt with the other ...

Other than that, it sounds like a encoding problem. Try storing the data as binary or encode the string with your databases collation.

Basically encryption gives you bytes but you store them as a string (encoded bytes).

THC4k
Yes, Encrypting using public key and decrypting using private key.
Tara Singh