sed ':a;N;$!ba;s/\n/\\n/g' certificate_file_name_or_key_file_name | sed 's/^[ \t]*//;s/[ \t]*$//'
Let's break it down step by step.
1. sed ':a;N;$!ba;s/\n/\\n/g' certificate_file_name_or_key_file_name
:
:a
: Define a label called 'a'.N
: Append the next line of input to the current pattern space (with an embedded newline).