# Is a symmetric encryption key derivable using the input and the output?

I am looking for a python library for encrypting a string with a single key. I do not want the key to derivable by knowing the input and the output. I have came to cryptography.fernet so far, but I am not sure if this will fulfill my needs. Can the encryption key be derived by knowing the algorithm (assuming the fernet algorithm in this case) and knowing the input and the output?

For example when I encrypt message A with key K and it outputs B, can somehow A and B be put together, so it will output K?

EDIT

The actual use of this is the following. I need to store a password in a place that others can see (a discord config channel, but that is secondary) in a way so they cannot see the actual password. I thought that the user would encrypt the password one-time with a key only visible to the bot (a discord bot) (with a command). The encrypted password would then be sent back to the user and stored in the channel for the bot to decrypt it and use it later. The problem is: if the user knows the input and the output, if he would be able to guess the key, he would then be able to decrypt all other passwords stored this way. And absolutely noone wants this to happen!

• Welcome to Cryptography. What do you mean by reversible? What you want may be, given plaintexts-ciphertexts pairs, it should be almost impossible to derive the key. AES is known to be secure this kind of attacks, or you can use ChaCha. The library part is off-topic here. So your question is better, Can AES (or your symmetric cipher) be broken by known-plaintext attack? Or you can mention your real problem in better words. You can edit your question. – kelalaka Aug 29 '19 at 17:36
• For passwords, I advise you to look at one of the top questions of information security How to securely hash passwords? – kelalaka Aug 29 '19 at 18:24
• Thank you, but I did not plan on storing it in a database. I have to store them in the channel. I am doing an automation, which requires some passwords to be known. – Jakub Bláha Aug 29 '19 at 18:47

For example when I encrypt message A with key K and it outputs B, can somehow A and B be put together, so it will output K?
Except for encryption messages where you are specifically restricted to use a specifc key K only once (e.g. OTP), then no, it is infeasible to recover K from A and B.