One way to enclose binary data in an XML document is to base-64 encode the value. Otherwise (as you have discovered) the data are apt to include characters that aren't legal in XML data streams. XML does allow some control characters, but only U+0009 (tab), U+000A (LF), and U+000D (CR).
Using base64 does require, of course, (a) that whatever system you are using to generate the XML has a function for performing base64 encoding (if you have an encryption library to produce the PKCS7, I'm guessing you have a base64 encoding function), and (b) that all the systems that consume the XML you are producing know to expect the value to be base64-encoded. If you are using an XSD schema to define the contract between data sources and data sinks, the schema can easily be made to say the value of the element in question must be base-64 encoded. Otherwise, you just have to document the fact.