Apply function to update_option Variable

There is no safe way to encrypt a password which is also reversible. The whole point of a hash function, such as is used for passwords, is that it is one-way.

You can encrypt it, not decrypt it.

If the password is decryptable, then you might as well not have the encryption in the first place. The point of encrypting passwords in the database is so that if somebody gets read-access to the database, they can’t find out what your passwords are. All they see is hashed randomness. Since it’s not reversible, then they can’t decrypt it themselves.

You say that you need to store info in the database in an encrypted form, but you don’t say why you need to do this. What is the specific type of threat or attack which you are protecting against, exactly? Every type of attack has countermeasures, you don’t just encrypt because encryption magically makes things safer, you encrypt in specific ways to mitigate specific threats.

If you’re communicating with some service, perhaps, then you might be better off using OAuth2 or similar to have the two services connect without the use of passwords.

Look for a better solution, at the high level. If you’re encrypting passwords and then also need to decrypt them, you’ve probably gone way wrong in the initial concept in the first place.