In case of the certificate, there'sthere are only onetwo problematic charactercharacters: a slash and newline. You can use parameter expansion to replace itthem by \/ and \n whichrespectivelly which sed understands:
sed "s/text/$var=${var//$'\n'/\\n/}
var=${var//\//\\\/}
sed "s/text/$var/"
But in general, I'd use Perl which knows which characters come from a variable and what characters are part of the syntax:
var=$var perl -pe 's/text/$ENV{var}/'