how to encyrpt DB_PASSWORD in wp-config

Encrypting the DB-Password in the wp-config.php is of no use, neither in your use-case nor in any other.

What is encrypted, has to be decryptable by the system in order to access the database, which means if an attacker is able to get your wp-config.php, he can get everything he needs to decrypt the encrypted password.

For your use case (preventing wp-config to be downloadable if the php-handler is not set), you can put your wp-config.php in a folder that is not accessible by web. Further information can be found here.