encrypt_keys( $input, $old_data ); } /** * Sanitize the secret key provided by the admin. * Encrypt the secret key and store in the db. * * @since 1.0.0 * * @param string $input Secret key input by the user. */ public function validate_secret_key( $input ) { $old_data = get_option( Db_Constants::AWS_SECRET_KEY ); return $this->encrypt_keys( $input, $old_data ); } /** * Encrypt the keys provided by the user. * If the data already exists in the database, then do not retrieve and print it on the viewer page. * Else encrypt the data and store it in the db. * * @since 1.0.0 * * @param string $input Key input by the user to encrypt. * @param string $old_data The data if already stored in the database. */ private function encrypt_keys( $input, $old_data ) { if ( ! isset( $input ) || trim( $input ) === '' ) { return $input; } elseif ( $input == Plugin_Constants::AWS_SECRET_KEY_MASK ) { return $old_data; } $output = base64_encode( openssl_encrypt( $input, Plugin_Constants::ENCRYPTION_ALGORITHM, Plugin_Constants::ENCRYPTION_KEY, 0, Plugin_Constants::ENCRYPTION_IV ) ); return $output; } } ?>