What are the best practices for securely storing and accessing passwords retrieved from an API in PHP?

Storing and accessing passwords retrieved from an API securely in PHP involves using encryption techniques and secure storage methods to protect sensitive information from unauthorized access.

// Encrypt the password before storing it
$encryptedPassword = openssl_encrypt($apiPassword, 'AES-256-CBC', 'secret_key', 0, '16_character_iv');

// Store the encrypted password in a secure location (e.g., database)
$encryptedPassword = base64_encode($encryptedPassword);

// Decrypt the password when needed
$decryptedPassword = openssl_decrypt(base64_decode($encryptedPassword), 'AES-256-CBC', 'secret_key', 0, '16_character_iv');