I'm a bit of a layman here and would be after a Python-based solution to this.

I would want a python-based application approach that is capable of generating data (e.g. csv file) that is locked immediately upon writing it, and it is not possible for the user to decrypt its contents on that end but rather a proxy individual (who holds a the encryption key or cipher, for example).

Hopefully that makes sense? Would love some help on this!

  • $\begingroup$ What does keep the user from keeping a database where |i|p[i]|c[i] | is a row of plaintext and the corresponding ciphertext? What is your actual aim? $\endgroup$
    – kelalaka
    Sep 24, 2022 at 19:05
  • $\begingroup$ Please read this answer I did a while back as it should answer this question too without me having to repeat myself. $\endgroup$ Sep 24, 2022 at 19:35
  • $\begingroup$ Asymmetric cryptography perchance? nitratine.net/blog/post/… $\endgroup$
    – Paul Uszak
    Sep 24, 2022 at 20:22

2 Answers 2


Yes, this is possible using RSA asymmetric encryption. There are two keys, one public, which is used for encryption, and one private, which is used for decryption. You will create data (e.g. csv formatted string) in python that will only be stored in RAM memory, that will look something like this:


Then using your python application you will encrypt data using the proxy user's public RSA key and write it to your file system. Please keep in mind that this way you can only encrypt data as large as the RSA key length, so if you have 2,048-bit RSA key, you can only encrypt data up to 2,048 bits long. Also, asymmetric encryption isn't that fast. Because of this, RSA isn't intended for raw data encryption. In addition, using public key cryptography doesn't make sense without PKI.

Maybe a better solution would be implementing key exchange (e.q. Diffie-Hellman) between python application and proxy individual and then encrypting the data with the exchanged key using symmetric encryption (e.q. AES-256).

  • $\begingroup$ "... you can only encrypt data as large as the RSA key length, so ..." No. Nowadays, we use (some padded form of) RSA to encrypt a key which is then used to encrypt the data using symmetric-key cipher. $\endgroup$
    – DannyNiu
    Dec 3, 2022 at 5:29

As noted by others, a user can create a ciphertext that they themselves cannot later decrypt by using assymetric cryptography.

  • Generate assymetric key pair $K_1, K_2$
  • Give $K_1$ to the user
  • User can encrypt plaintext $P$ as ciphertext $C=encrypt(K_1,P)$
  • Only key $K_2$ can decrypt $C$ so the user that only has $K_1$ cannot decrypt it

This approach requires the user to have some sort of access to the plaintext. It seems like your goal is for the user not to gain knowledge of $P$ either, and this is trickier to do. If they have full access to the hardware the program is running on then it's near impossible to completely protect the data the program generates.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.