File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,6 +76,9 @@ Features:
7676- Add optional $options constructor argument on XMLSecurityDSig; pass
7777 'stripWhitespace' => true (default false) to build signatures from a
7878 compact template with no whitespace between elements (BASE_TEMPLATE_NOWS)
79+ - Add optional $options constructor argument on XMLSecEnc; pass
80+ 'stripWhitespace' => true (default false) to build EncryptedData from a
81+ compact template with no whitespace between elements (template_NOWS)
7982
8083Notes:
8184- Prefer RSA-OAEP and AES-GCM for new deployments; RSA-1.5 and CBC remain
@@ -92,6 +95,9 @@ Bug Fixes:
9295- Compact signature template (XMLSecurityDSig 'stripWhitespace' option) removes
9396 inter-element whitespace that caused signature mismatch with C# SignedXml and
9497 Python signxml.
98+ - Compact encryption template (XMLSecEnc 'stripWhitespace' option) removes
99+ inter-element whitespace from EncryptedData for peers that reject significant
100+ whitespace between elements.
95101
9610212, Dec 2025, 3.1.5
97103Security:
Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ class XMLSecEnc
5656 </xenc:CipherData>
5757</xenc:EncryptedData> " ;
5858
59+ const template_NOWS = "<xenc:EncryptedData xmlns:xenc='http://www.w3.org/2001/04/xmlenc#'><xenc:CipherData><xenc:CipherValue></xenc:CipherValue></xenc:CipherData></xenc:EncryptedData> " ;
60+
5961 const Element = 'http://www.w3.org/2001/04/xmlenc#Element ' ;
6062 const Content = 'http://www.w3.org/2001/04/xmlenc#Content ' ;
6163 const URI = 3 ;
@@ -130,8 +132,19 @@ class XMLSecEnc
130132 /** @var array */
131133 private $ references = array ();
132134
133- public function __construct ()
135+ /** @var string */
136+ private $ activeTemplate ;
137+
138+ /**
139+ * @param null|array $options Optional flags; use 'stripWhitespace' => true for a compact template
140+ */
141+ public function __construct ($ options =null )
134142 {
143+ $ stripWhitespace = false ;
144+ if (is_array ($ options )) {
145+ $ stripWhitespace = !isset ($ options ['stripWhitespace ' ]) ? false : (bool ) $ options ['stripWhitespace ' ];
146+ }
147+ $ this ->activeTemplate = $ stripWhitespace ? self ::template_NOWS : self ::template;
135148 $ this ->_resetTemplate ();
136149 }
137150
@@ -157,7 +170,7 @@ public function enableLegacyMode()
157170 private function _resetTemplate ()
158171 {
159172 $ this ->encdoc = new DOMDocument ();
160- $ this ->encdoc ->loadXML (self ::template );
173+ $ this ->encdoc ->loadXML ($ this -> activeTemplate );
161174 }
162175
163176 /**
You can’t perform that action at this time.
0 commit comments