robrichards/xmlseclibs
소개
A PHP library for XML Security
보안 및 개인정보 보호측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original#xmlseclibs
xmlseclibs is a library written in PHP for working with XML Encryption and Signatures.
The author of xmlseclibs is Rob Richards.
Branches
- master: 5.0.x (unreleased, planned December 2026); requires PHP version 8.3+
- 4.0: unsupported; requires PHP 8.0+
- 3.1: Added AES-GCM support requiring 7.1+
- 3.0: Removes mcrypt usage requiring 5.4+ (5.6.24+ recommended for security reasons)
- 2.0: Contains namespace support requiring 5.3+
- 1.4: Contains auto-loader support while also maintaining backwards compatiblity with the older 1.3 version using the xmlseclibs.php file. Supports PHP 5.2+
See SECURITY.md for supported versions and reporting instructions.
Requirements
xmlseclibs requires PHP version 8.3 or greater and phpseclib 3.0.58 or later. OpenSSL is optional (phpseclib is used for crypto).
Security notes
Prefer the safe-by-default verifier
verifyDocument()(see below). It requires a caller-supplied (pinned) key, never derives the key from the document'sKeyInfo, enforces an algorithm allowlist for both theSignatureMethodand everyDigestMethod, and only reports success when every reference validated. It checks the signature before reference lookup, reference canonicalization, or digest computation. It accepts only canonicalization and enveloped-signature transforms, and returns the validated nodes for you to operate on. A failed call leaves no validated nodes, including nodes from an earlier successful call on the same object.If you use the low-level primitives directly,
$objDSig->verify($key)and$objKey->verifySignature($data, $signature)have three outcomes:1(verified),0(the signature does not match) and anException(verification could not be completed, for example aSignatureValuethat is not valid Base64, or a key that is missing or of the wrong type). They return only the integers1or0; there is no-1. Keep checking with a strict comparison ($objDSig->verify($key) === 1). To treat every failure as an ordinary rejection, catch the exception at your verification boundary. See Migrating verify() error handling.After a successful
validateReference(),getValidatedNodes()returns the reference target. That node may hold content outside the transformed data that was digested, so callers using XPath filtering must apply their own understanding of the transforms. For an enveloped signature, the returned node still contains the Signature element and its descendants. Do not re-select assertions by Id from the whole document. A failedvalidateReference()orverify()leaves no validated nodes, including when an earlier reference in that call had already matched. A return of1fromverify()leaves those nodes in place.Read element values with
textContentrather thanfirstChildornodeValue. Comments are excluded from the digest of same-document references.Do not trust a signing certificate from
KeyInfoalone. Load and pin trusted keys yourself.Signature verification (
verifyDocument()as well asverify()/validateReference()) accepts by default only SHA-256/384/512 digests and RSA-SHA-256/384/512 (and RSA-PSS) and ECDSA-SHA-256/384/512 signatures ($objDSig->allowedSignatureAlgorithms/$objDSig->allowedDigestAlgorithmsdefault toXMLSecurityDSig::DEFAULT_SIGNATURE_ALGORITHMS/DEFAULT_DIGEST_ALGORITHMS). To accept SHA-1 (rsa-sha1, hmac-sha1 and sha1 digests) and RIPEMD-160 digests, call$objDSig->enableLegacyMode()or widen the lists explicitly, e.g.$objDSig->allowedSignatureAlgorithms[] = XMLSecurityKey::RSA_SHA1;and$objDSig->allowedDigestAlgorithms[] = XMLSecurityDSig::SHA1;(orXMLSecurityDSig::RIPEMD160). DSA signatures are not supported. Both lists are always arrays: null is rejected with aTypeError, and an empty array allows no algorithm.verify(),validateReference()andverifyDocument()apply the same lists. ReserveXMLSecurityDSig::SUPPORTED_SIGNATURE_ALGORITHMS/SUPPORTED_DIGEST_ALGORITHMSfor callers that deliberately want every supported algorithm in that category. See Migrating null algorithm allowlists if you previously assigned null. Signing is unaffected. ECDSA keys are limited to the P-256, P-384 and P-521 curves (XMLSecurityKey::EC_CURVE_OIDS); to accept another curve, add it explicitly to$objKey->allowedECCurves.Prefer RSA-OAEP and AES-GCM for encryption. RSA-1.5 key transport is denied by default on decryption (Bleichenbacher risk); opt in with
$objenc->allowRSA15KeyTransport = true;plus$objenc->allowedKeyAlgorithms[] = XMLSecurityKey::RSA_1_5;only for legacy interop. Key transport is restricted by default to RSA-OAEP ($objenc->allowedKeyAlgorithmsdefaults toXMLSecEnc::DEFAULT_KEY_ALGORITHMS); widen the list explicitly (XMLSecEnc::SUPPORTED_KEY_ALGORITHMSlists every supported algorithm). The lists are always arrays: null is rejected with aTypeError, and an empty array allows no algorithm. Symmetric data encryption (an EncryptedData whose EncryptionMethod is AES or 3DES) accepts only AES-GCM by default ($objenc->allowedDataAlgorithmsdefaults toXMLSecEnc::DEFAULT_DATA_ALGORITHMS). An EncryptedData encrypted directly with an RSA key-transport algorithm is governed byallowedKeyAlgorithmsandallowRSA15KeyTransport, notallowedDataAlgorithms. AES-CBC and TripleDES-CBC require$objenc->enableLegacyMode()(addsXMLSecEnc::LEGACY_DATA_ALGORITHMS) or an explicit list. To accept every data-encryption algorithm, assignXMLSecEnc::SUPPORTED_DATA_ALGORITHMS. Encryption still uses the algorithm of the caller-supplied key.encryptKey()accepts only a key-transport algorithm (RSA-1.5, RSA-OAEP, RSA-OAEP-MGF1P). A symmetric key must be at least as long as its algorithm requires (AES-128: 16 bytes, AES-192: 24, AES-256: 32, TripleDES: 24, CBC and GCM); longer keys are truncated to that length.verifyDocument()checks the signature, then accepts only the canonicalization algorithms this library supports (c14n, c14n with comments, exclusive c14n, exclusive c14n with comments) and the enveloped-signature transform. Any other transform, including XPath, is rejected before it is applied. This holds in legacy mode. There is no setting that allows other transforms on this path.On the low-level path (
validateReference(),verify(),getValidatedNodes()), XPath (REC-xpath-19991116) transforms are rejected unless$objDSig->allowXPathTransformsis true (enableLegacyMode()sets it). The node returned for a reference is the reference target and may hold content outside the transformed data that was digested.Only one XPath transform per reference is supported, when signing and when verifying.
$maxXPathTransformsremains for compatibility and is effectively capped at 1; a lower value is still honored.$maxXPathNamespaces(default 20) still limits namespaces on that transform.add509Cert(..., $isURL = true)fetches over http/https only and rejects hosts that resolve to loopback/private/link-local/reserved/CGNAT addresses, with redirects disabled. The connection is made to an address that passed this check, and the host name is not looked up again for the connection, so a later DNS answer cannot change where the certificate is downloaded from.file://is disabled unless you passarray('allow_file_scheme' => true)in$options. Only fetch certificates from trusted URLs.Decrypted XML containing a
DOCTYPEis rejected to guard against entity-expansion / XXE. Always load untrusted input documents yourself with DTD/entity processing disabled.Documents carrying a
DOCTYPEare rejected during signature verification (locateSignature()/verifyDocument()). This closes the entity-reference bypass in which anId="&e;"attribute is resolved bygetAttribute()but is invisible to the XPath reference lookup (a libxml2 hashing bug, the same root cause as CVE-2025-23369), causingverify()to validate a different node than the one your application reads. Set$objDSig->forbidDoctype = falseonly if you fully trust the document source and require DTD support.Legacy interoperability (temporary): if you must accept documents/peers that rely on pre-4.0 behaviour, call
$objDSig->enableLegacyMode()and/or$objenc->enableLegacyMode()once after construction. That restores the interoperability settings in one place (DOCTYPE allowed on verify, XPath transforms allowed on the low-level verify path with at most one per reference, SHA-1 signature and digest algorithms and RIPEMD-160 digests accepted on verify, RSA-1.5 key transport allowed, AES-CBC and TripleDES-CBC data decryption allowed). It does not change the transformsverifyDocument()accepts, SignatureMethod/key binding, uniform decryption errors, or DOCTYPE rejection in decrypted XML. Prefer migrating peers and removing the call.
Upgrading from 4.0.x to 5.0
This release requires PHP 8.3 or later (4.0.x required PHP 8.0 or later) and phpseclib 3.0.58 or later (4.0.2 required 3.0.57 or later).
Upgrading from 3.1.x? Also read Upgrading from 3.1.x to 5.0: stored documents and keys.
- The algorithm allowlists are always arrays and default to
DEFAULT_*forverify(),validateReference(), and decryption, not only forverifyDocument(). In 4.0.x, a null algorithm allowlist skipped the corresponding list check during low-level signature verification, digest validation, or decryption. RSA-1.5 key transport still required its separate opt-in. In 4.0.x,verifyDocument()used the corresponding default for each allowlist set to null. In 5.0, assigning or passingnullthrows aTypeError. SHA-1 signatures, SHA-1 and RIPEMD-160 digests, and AES-CBC or TripleDES-CBC data decryption needenableLegacyMode()or entries on the corresponding list. See Migrating null algorithm allowlists. verify()andverifySignature()return only1or0; a processing error throws instead of returning-1. See Migrating verify() error handling. The same return values and exception behavior apply in legacy mode.- Removed methods:
XMLSecurityDSig::generate_GUID()(usegenerateGUID()) andXMLSecurityKey::getAlgorith()(usegetAlgorithm()).XMLSecurityDSig::appendCert()was an empty stub: remove the call, or useadd509Cert()if you intended to add a certificate. - Signing requires a signature key type (for example,
XMLSecurityKey::RSA_SHA256orXMLSecurityKey::ECDSA_SHA256), not an encryption or key-transport type such asRSA_1_5orRSA_OAEP.signData()andXMLSecurityDSig::sign()throw for this misuse, before emitting a SignatureMethod.XMLSecurityDSig::verify()throws for a non-signature key type as well.verifySignature()returns0for those key types. This also applies in legacy mode. Encryption and key transport are unchanged. verifyDocument()accepts only canonicalization and enveloped-signature transforms, including in legacy mode.- Only one XPath transform per reference is supported, when signing and when verifying.
$maxXPathTransformsis effectively capped at 1; a lower value is still honored. - SignedInfo is checked against
$maxSignedInfoNodes(defaultXMLSecurityDSig::MAX_SIGNEDINFO_NODES, 10000) and$maxSignedInfoNamespaces(defaultXMLSecurityDSig::MAX_SIGNEDINFO_NAMESPACES, 1000) before it is canonicalized, when signing and when verifying, in default and legacy mode. See Large SignedInfo. - Key transport is restricted by default to RSA-OAEP (
$allowedKeyAlgorithmsdefaults toXMLSecEnc::DEFAULT_KEY_ALGORITHMS). Decrypting RSA-1.5 requires bothallowRSA15KeyTransport = trueand RSA-1.5 in the list;enableLegacyMode()does both. - An EncryptedKey requires a key-transport algorithm (RSA-1.5, RSA-OAEP, RSA-OAEP-MGF1P).
encryptKey()rejects any other wrapping key before changing the document. A symmetric key shorter than the algorithm requires is rejected (AES-128: 16 bytes, AES-192: 24, AES-256: 32, TripleDES: 24, CBC and GCM); longer keys are still truncated to that length. staticLocateKeyInfo()andXMLSecurityKey::fromEncryptedKeyElement()have two new optional parameters ($allowedKeyAlgorithms,$allowedDataAlgorithms), which default toDEFAULT_*. Subclasses that override either method with the 4.0.x signature need to add those parameters.add509Cert()limits a certificate downloaded over http or https toXMLSecurityDSig::MAX_REMOTE_CERT_BYTES(1048576 bytes, 1 MiB).add509Cert()checks every address that a certificate URL host resolves to, in default and legacy mode, and opens nothing if any address is refused. The host is resolved only by A/AAAA lookups through PHP'sdns_get_record(). An alias (CNAME) is followed, with up to eight additional lookups for CNAME-only answers, to its final addresses, all of which are checked; the connection then goes to one of them. The URL's host name stays in theHostheader, including a trailing dot when the URL has one; TLS verification and SNI use that host name with one trailing dot removed. If a lookup fails, an alias loops or is too deep, or no address is found, the fetch is refused. IPv4 addresses in the IANA IPv4 Special-Purpose Address Registry blocks that are not globally reachable, and multicast, are refused. IPv6 addresses must be in the global-unicast range2000::/3, outside the IANA IPv6 Special-Purpose Address Registry blocks that are not globally reachable; 6to4 (2002::/16), Teredo (2001::/32) and the standard NAT64 prefixes (64:ff9b::/96,64:ff9b:1::/48) are refused. IPv4-mapped and IPv4-compatible IPv6 addresses are judged by, and connected to through, their embedded IPv4 address. A NAT64 prefix that a network places inside its own global-unicast space cannot be identified by these checks. If your DNS64 service uses a blocked translation prefix, fetch the certificate through your application's trusted transport and pass its contents to xmlseclibs.- The
Hostheader of a certificate download keeps a non-default port and brackets IPv6 literals. For a host name, the server certificate is verified against that name, which is also sent as SNI. For an IP-literal URL, the server certificate is verified against the IP address and no SNI is sent. xmlenc11#rsa-oaepciphertext written with SHA-256/MGF1-SHA256 where those parameters were omitted from the XML does not decrypt through default key resolution. See RSA-OAEP parameters and compatibility for regeneration or explicit key configuration withsetOAEPParameters().- The built-in
XMLSecurityKeyno longer decrypts anEncryptedDataencrypted directly with an RSA-1.5 key (noEncryptedKey), including documents produced by 3.1.x, even with the RSA-1.5 opt-in orenableLegacyMode(). Direct RSA-1.5 encryption withencryptNode()orencryptReferences()requiresallowRSA15KeyTransport = true. RSA-1.5EncryptedKeydecryption with a correctly sized session key is still supported withenableLegacyMode()or the explicit opt-in. When the expected session key size is known (locateKeyInfo()andstaticLocateKeyInfo()set it), a decrypted session key of any other length is replaced with random bytes of that size. 4.0.x replaced only lengths other than 16, 24 or 32 bytes, so a 24- or 32-byte session key for AES-128, or a 32-byte key for AES-192 or TripleDES, no longer yields the original data. For 3.1.x documents with longer session keys, see Encrypted documents. See EncryptedData encrypted directly with RSA-1.5. decryptNode()with$replace = trueand a Type ofXMLSecEnc::ElementorXMLSecEnc::Contentreports failures that depend on the ciphertext, in the built-in decryption and in the library's XML replacement, with one public exception:Exceptionwith the messageXMLSecurityKey::DECRYPTION_FAILURE("Failure decrypting Data"). This includes decrypted data that is not well-formed XML or contains a DOCTYPE, which previously threw "Error parsing decrypted XML" or "Decrypted XML must not contain a DOCTYPE". The document is left unchanged. Undoing a partial replacement uses the document's own DOM methods, so a registered node class that also refuses those calls can still leave the document changed. Errors for the key, the algorithm policy, the node to decrypt and the direct RSA-1.5 restriction keep their messages, and exceptions thrown by a customdecryptData()implementation propagate unchanged.$replace = falseis unchanged. This also applies in legacy mode.- A reference to the document element by ID (
URI="#id") digests only that element and its descendants. Earlier versions, including 3.1.5 and 4.0.2, digested the whole document instead when no processing instruction came before the document element, so a processing instruction after it was part of the digest. The digest therefore differs only for a document element with no processing instruction before it and at least one after it; with a processing instruction before the document element, earlier versions already digested the element alone and both versions agree. Signatures created by earlier versions over that pattern do not verify by default;enableLegacyMode()sets$objDSig->acceptPre5RootElementDigests, which also accepts the earlier digest. That option affects verification only: signing, including in legacy mode, always uses the new digest, so earlier versions do not verify new signatures over a document with that pattern. In a mixed-version rollout where documents use that pattern, upgrade verifiers before signers. A reference with no URI orURI=""still covers the whole document.
Large SignedInfo
XMLSecurityDSig checks SignedInfo before canonicalizing it in sign(), verifyDocument(), verify() and canonicalizeSignedInfo(). $maxSignedInfoNodes counts SignedInfo itself, every node below it (elements, text including whitespace-only text, comments, CDATA sections and processing instructions) and every ordinary attribute in that subtree. $maxSignedInfoNamespaces counts the namespace declarations on the ancestors of SignedInfo, on SignedInfo and on every element below it; a redeclaration of a prefix counts again. A SignedInfo exactly at a limit is accepted and one over is rejected with an Exception. The check reads each ancestor and then each node of SignedInfo once, and stops at the element that takes either count over its limit; that element's attribute and declaration names are read in full. A signature with many References can exceed the default node limit (each Reference with two transforms adds about 11 nodes). To sign and verify such signatures, raise the value on both the signer and the verifier, for example $objDSig->maxSignedInfoNodes = 20000;; PHP_INT_MAX removes a limit. enableLegacyMode() does not change either limit. A signer checks the namespace declarations present when sign() runs; with sign($key, $parent) that includes the parent's ancestors, so a Signature appended to another location later can have more declarations in scope at verification.
See Legacy mode for enableLegacyMode() in 5.0.
Migrating null algorithm allowlists
Assigning or passing null for $allowedSignatureAlgorithms,
$allowedDigestAlgorithms, $allowedKeyAlgorithms or
$allowedDataAlgorithms (including the arguments of
staticLocateKeyInfo() and fromEncryptedKeyElement()) now throws a
TypeError. An empty array allows no algorithm. Choose the replacement
based on what the null assignment was for.
verifyDocument(): on a fresh instance, remove the assignment (the
properties already default to DEFAULT_*). To reset an already
configured instance, assign the corresponding DEFAULT_* constant:
$dsig = new XMLSecurityDSig();
// Previously: $dsig->allowedSignatureAlgorithms = null;
// Previously: $dsig->allowedDigestAlgorithms = null;
$dsig->verifyDocument($key, $doc);
// Already configured:
$dsig->allowedSignatureAlgorithms = XMLSecurityDSig::DEFAULT_SIGNATURE_ALGORITHMS;
$dsig->allowedDigestAlgorithms = XMLSecurityDSig::DEFAULT_DIGEST_ALGORITHMS;
Do not switch a verifyDocument() caller from null to a SUPPORTED_*
constant. That broadens the policy to include SHA-1 and RIPEMD-160.
Low-level verification or decryption: list the algorithms the integration requires, for example:
$dsig->allowedSignatureAlgorithms[] = XMLSecurityKey::RSA_SHA1;
$dsig->allowedDigestAlgorithms[] = XMLSecurityDSig::SHA1;
$enc->allowedKeyAlgorithms[] = XMLSecurityKey::RSA_1_5;
$enc->allowRSA15KeyTransport = true;
$enc->allowedDataAlgorithms[] = XMLSecurityKey::AES256_CBC;
Reserve XMLSecurityDSig::SUPPORTED_SIGNATURE_ALGORITHMS,
SUPPORTED_DIGEST_ALGORITHMS, XMLSecEnc::SUPPORTED_KEY_ALGORITHMS and
SUPPORTED_DATA_ALGORITHMS for callers that deliberately want every
supported algorithm in that category.
Legacy mode: a null assignment still needs an edit, even if the
next line calls enableLegacyMode(). For the standard legacy profile,
remove the null assignment and call enableLegacyMode() on the default
configuration:
$dsig = new XMLSecurityDSig();
$dsig->enableLegacyMode();
$enc = new XMLSecEnc();
$enc->enableLegacyMode();
That call enables several compatibility settings at once:
XMLSecurityDSig::enableLegacyMode()setsforbidDoctypeto false (a DOCTYPE is allowed when locating a signature), setsallowXPathTransformsto true (XPath is allowed on the low-level verify path, at most one transform per reference), raises$maxXPathTransformsand$maxXPathNamespaces, and adds rsa-sha1 and hmac-sha1 to$allowedSignatureAlgorithmsand the sha1 and ripemd160 digests to$allowedDigestAlgorithms.XMLSecEnc::enableLegacyMode()setsallowRSA15KeyTransportto true, adds RSA-1.5 to$allowedKeyAlgorithms, and adds AES-CBC and TripleDES-CBC (LEGACY_DATA_ALGORITHMS) to$allowedDataAlgorithms.
verifyDocument() still accepts only canonicalization and
enveloped-signature transforms. If only one additional algorithm is
needed, widen just that list instead of calling enableLegacyMode().
Subclasses: redeclaring the public allowlist properties requires the
compatible array type. Otherwise-compatible overrides of
staticLocateKeyInfo() and fromEncryptedKeyElement() may keep a
?array or untyped parameter.
Migrating verify() error handling
XMLSecurityDSig::verify() and XMLSecurityKey::verifySignature() now report three distinct outcomes:
| Outcome | Result |
|---|---|
| Verified | returns 1 |
| Signature mismatch | returns 0 |
| Verification could not be completed | throws an Exception |
Earlier versions returned -1 for the third outcome. The return value is still an integer and is only ever 1 or 0; it is not a bool. verify() throws if the supplied key's verifySignature() returns any other value.
Checks of the form $objDSig->verify($key) === 1 keep working for valid and mismatched signatures. On a processing error that expression previously evaluated to false. It now throws before the comparison runs. This also affects callers that never checked for -1.
Processing errors include a SignatureValue that is not valid Base64, a key that has not been loaded or cannot be parsed, a key of the wrong type for the algorithm (for example an EC key used with an RSA algorithm, or private key material where a public key is required), and asymmetric key material used as an HMAC key. A key type that is not a signature key keeps its existing behavior: verifySignature() returns 0 and verify() throws.
If you need every verification failure to become an ordinary rejection, catch the exception at your verification boundary:
try {
$verified = ($objDSig->verify($objKey) === 1);
} catch (Exception $e) {
$verified = false; // verification could not be completed
}
After a 0 result or an exception, getValidatedNodes() returns null, including when the same object had previously succeeded. The same verification return values and exception behavior apply in legacy mode.
Upgrading from 3.1.x to 5.0: stored documents and keys
This section collects the changes since 3.1.x that affect documents, keys and certificates an application may already have stored. The full lists are in Upgrading from 3.1 to 4.0 and Upgrading from 4.0.x to 5.0.
Signed documents
SHA-1 and RIPEMD-160 digests. 3.1.x signatures that use rsa-sha1, hmac-sha1, a sha1 digest or a ripemd160 digest verify with
$objDSig->enableLegacyMode(). To accept only RIPEMD-160 digests, add that one entry instead:$objDSig = new XMLSecurityDSig(); $objDSig->allowedDigestAlgorithms[] = XMLSecurityDSig::RIPEMD160;References that relied on 3.1.x removing the Signature. 3.1.x removed the Signature element from the document before computing every reference digest, so a Reference whose content contained the Signature verified even when none of its transforms excluded it. Since 4.0 the digest is computed over the referenced content as its transforms describe. A Reference whose content does not contain the Signature (for example one that points by ID to a sibling element of the Signature) still verifies, and so does one whose XPath transform excludes the Signature, on the low-level path where XPath transforms are allowed (
enableLegacyMode()orallowXPathTransforms;verifyDocument()does not accept XPath transforms in any mode). Only a signature whose referenced content contains the Signature, with no enveloped-signature transform or other transform that excludes it, fails withReference validation failed, in every mode. Re-sign only those documents, with the transform:$objDSig->addReference( $doc->documentElement, XMLSecurityDSig::SHA256, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature', XMLSecurityDSig::EXC_C14N) );Signature element kept in the document.
validateReference()no longer removes the Signature element from the caller's document; see Upgrading from 3.1 to 4.0.Document element referenced by ID with a trailing processing instruction: see Upgrading from 4.0.x to 5.0. Legacy mode also accepts the digest 3.1.x computed.
WithComments references: only a signature whose original digest included comments inside the referenced content is affected. For the same-document forms (an omitted URI,
URI=""andURI="#id"), verification omits those comments, so the digest does not match; 3.1.x could not verify such signatures either (see the 5.0.0 CHANGELOG). Re-sign those documents. A WithComments signature over content without comments, or with comments only outside the referenced content, is not affected.
Encrypted documents
EncryptedData encrypted directly with RSA-1.5 (no EncryptedKey) does not decrypt with the built-in
XMLSecurityKeyin any mode; see EncryptedData encrypted directly with RSA-1.5. An RSA-1.5 EncryptedKey with a correctly sized session key still decrypts with$objenc->enableLegacyMode()or the explicit opt-in; for a longer session key, see the next item.RSA-1.5 EncryptedKey with a longer decrypted session key. 3.1.x used the leading bytes of a decrypted session key that was longer than the data algorithm's key, so a sender that loaded a longer key (for example 48 bytes for AES-256) produced documents that 3.1.x decrypted. Keys created with
generateSessionKey()have the exact size and are not affected. In 5.0:- Without RSA-1.5 enabled, the document is declined by the algorithm policy before the session key is decrypted, as every RSA-1.5 EncryptedKey is.
- With RSA-1.5 enabled (
enableLegacyMode()or the explicit opt-in) and the expected session key size known (locateKeyInfo()andstaticLocateKeyInfo()set it from the data key or the EncryptedData), a decrypted session key of another length is replaced with random bytes of the expected size, and data decryption continues with that key. The built-in path cannot recover the original plaintext. Usually an exception follows, but CBC data can occasionally decrypt to other bytes, whichdecryptNode($key, false)then returns. An exception, or a particular message, is therefore not a reliable way to identify affected documents. - With no expected size set (for example a key from
fromEncryptedKeyElement()withoutsetExpectedSessionKeySize()), a decrypted session key of 16, 24 or 32 bytes is returned and the data key uses its leading bytes, as in 3.1.x. Any other length is replaced with 32 random bytes.
Ask the sender to re-encrypt affected documents. Otherwise convert them in an isolated, controlled process, as described under Existing documents in EncryptedData encrypted directly with RSA-1.5: an
XMLSecurityKeysubclass whosedecryptData()override performs the RSA-1.5 decryption with a provider you have chosen returns the decrypted session key at its full length, so the conversion can check that length. Load your private key into it, setisEncrypted = true, and pass it todecryptKey()on the EncryptedKey'sencryptedCtx; the data key then uses the leading bytes it needs. Re-encrypt the content with AES-GCM and RSA-OAEP, and do not use that reader for incoming documents.RSA-OAEP keys you construct yourself. In 3.1.x a key constructed as
XMLSecurityKey::RSA_OAEPused SHA-1 and MGF1-SHA1. Since 4.0 the constructor selects SHA-256 and MGF1-SHA256, so a hand-built private key no longer decrypts a 3.1.x EncryptedKey that omits the OAEP parameters. Resolve the key from the document (locateKeyInfo()), which applies the XML Encryption defaults, or select those defaults on your own key:$privateKey = new XMLSecurityKey(XMLSecurityKey::RSA_OAEP, array('type' => 'private')); $privateKey->setOAEPParameters(); // SHA-1 and MGF1-SHA1, empty label $privateKey->loadKey('./path/to/your-private-key.pem', true);
Keys and certificates
$objKey->keyholds the key bytes. In 3.1.xloadKey()replaced the publickeyproperty with an OpenSSL key object for RSA keys and certificates. Since 4.0 it holds the loaded string (the PEM, DER or raw key, or the PEM certificate). Code that passed it toopenssl_*functions must load an OpenSSL key itself (ext-openssl is optional):$handle = openssl_pkey_get_private($objKey->key, $objKey->passphrase);Private key passphrase. 3.1.x read
$objKey->passphraseonce, inloadKey(). Since 4.0 the key is parsed when it is used (signing or decryption), with the passphrase set at that time. Set the passphrase before use and keep it set for as long as the key object is used:$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type' => 'private')); $objKey->passphrase = $passphrase; $objKey->loadKey('./path/to/encrypted-privatekey.pem', true); // Do not clear $objKey->passphrase here; sign() reads it. $objDSig->sign($objKey);Local certificate files in
add509Cert(). In 3.1.xadd509Cert($path, true, true)read a local path. A path without a URL scheme now throwsInvalid certificate URL, andfile://requires an explicit option. Read the file in the application and pass its contents, or use thefile://option:$objDSig->add509Cert(file_get_contents('./path/to/mycert.pem')); // or $objDSig->add509Cert('file://' . realpath('./path/to/mycert.pem'), true, true, array('allow_file_scheme' => true));HMAC verification returns
1or0instead of a bool, andverify()throws when verification cannot be completed; see Migrating verify() error handling.
Upgrading from 3.1 to 4.0
These items landed in 4.0 and still apply. Items introduced in 5.0 are listed in Upgrading from 4.0.x to 5.0.
For documents, keys and certificates stored by a 3.1.x application, see Upgrading from 3.1.x to 5.0: stored documents and keys.
Platform
- PHP 8.0+ required (was 5.4+)
- 4.0 introduced the phpseclib 3 dependency and made
ext-openssloptional. As of 4.0.2, the minimum phpseclib version was 3.0.57.
Signature verification
- DOCTYPE rejected by default during verification (
locateSignature/verifyDocument). Opt out:$dsig->forbidDoctype = falseorenableLegacyMode() - XPath Filtering Transforms rejected by default on verify. Opt in:
$dsig->allowXPathTransforms = trueorenableLegacyMode(). Signing unchanged - XPath caps when enabled: in 4.0.x at most 5 XPath transforms per reference (
$maxXPathTransforms, the 4.0.x limit; 5.0 supports one, see Upgrading from 4.0.x to 5.0) and 20 namespaces per XPath transform ($maxXPathNamespaces).enableLegacyMode()raises both settings, and the one-transform limit of 5.0 still applies verify()always requires SignatureMethod === key algorithm; mismatch throws (not restored by legacy mode)- HMAC keys cannot be loaded from certificates or asymmetric keys
- References fail closed: unresolved, external, or duplicate-Id URIs throw; same-document only
- Unknown CanonicalizationMethod rejected
- HMAC verify returns
1/0— always check=== 1 - Returned nodes keep the Signature element. A successful
verifyDocument()returns each reference target.validateReference()returns true on success, and low-level callers retrieve the targets throughgetValidatedNodes(). For an enveloped signature, that node still contains theSignatureelement and its descendants. In 3.1.x the Signature was removed from the caller's document during verification. Check the expected element's name, namespace, and protocol-defined position, and read only the selected application children.
Encryption / decryption
- RSA-1.5 key transport denied by default. Opt in:
$enc->allowRSA15KeyTransport = trueorenableLegacyMode() - Single decrypt error message:
Failure decrypting Data(do not branch on exception text) - DOCTYPE rejected in decrypted XML (not restored by legacy mode)
- EncryptedKey/RetrievalMethod depth capped
- ISO 10126 pad length validated on CBC decrypt
Certificate URL fetch (add509Cert)
- Only
http/httpsby default;file://needs['allow_file_scheme' => true] - Private/loopback/link-local/reserved/CGNAT targets rejected; redirects disabled
- Connects to an address that passed the check; the host name is not looked up again for the connection
API signature changes (defaults preserve most callers)
processTransforms(..., $signing = false)staticLocateKeyInfo(..., $depth = 0, $allowRSA15 = false)fromEncryptedKeyElement(..., $depth = 0, $allowRSA15 = false)
Other API changes since 3.1.x
These came with 4.0 and still apply in 5.0. Legacy mode does not change them.
- Return types on
XMLSecurityKeymethods. Overrides in a subclass must declare the same or a compatible return type; otherwise PHP stops with a fatal error ("must be compatible"). The affected methods areloadKey(): void,serializeKey(): void,generateSessionKey(): string,getSymmetricKeySize(): ?int,getX509Certificate(): ?string,getX509Thumbprint(): ?stringand the staticfromEncryptedKeyElement(): XMLSecurityKey. XMLSecurityDSig::templateremoved. This unused constant held ads:-prefixed Signature template. The library has usedBASE_TEMPLATE(andBASE_TEMPLATE_NOWS) instead.loadKey()input. It takes the key text or, with$isFile = true, a file path. An OpenSSL key object cannot be used, and afile://URI passed as the key text (without$isFile) is no longer resolved. Pass the PEM contents, or the path with$isFile = true.encryptData()anddecryptData()called directly.- A private key cannot encrypt and a public key cannot decrypt; both throw. 3.1.x used
openssl_private_encrypt()andopenssl_public_decrypt(). - With a signature algorithm key such as
RSA_SHA256, 3.1.x used PKCS#1 v1.5. Since 4.0 the key uses RSA-OAEP with the key's digest (SHA-256 forRSA_SHA256), so ciphertext from 3.1.x does not decrypt with such a key, and ciphertext made by 4.0 or later is not read correctly by 3.1.x. To read 3.1.x PKCS#1 v1.5 data that is a session key, use a key of typeXMLSecurityKey::RSA_1_5(see the next item for its limits). - With an
RSA_1_5key and no expected session-key size,decryptData()returns the recovered plaintext only when it is 16, 24 or 32 bytes long. Otherwise it returns 32 random bytes. When an expected session-key size is set (setExpectedSessionKeySize(), whichlocateKeyInfo()andstaticLocateKeyInfo()call for you), only that exact length is accepted. A decryption failure or a length mismatch returns random bytes of the expected size. - Because of this, an
RSA_1_5key reads historical PKCS#1 v1.5 data only when the plaintext is a session key of 16, 24 or 32 bytes. For raw RSA data of any other length, which 3.1.x returned unchanged,decryptData()cannot return the plaintext. Decrypt such archives outside this library, in an isolated, controlled process (for example phpseclib'sRSAkey withRSA::ENCRYPTION_PKCS1padding), and re-encrypt the result with AES-GCM and RSA-OAEP.
- A private key cannot encrypt and a public key cannot decrypt; both throw. 3.1.x used
Legacy mode
$dsig->enableLegacyMode() / $enc->enableLegacyMode() restores DOCTYPE (verify), XPath transforms on the low-level verify path (at most one per reference), SHA-1 signature/digest algorithms and RIPEMD-160 digests (verify), pre-5.0 digests of a document element reference (verify), RSA-1.5, and CBC data decryption only (DSA signatures are not supported; on the signature side it adds rsa-sha1, hmac-sha1 and the sha1 and ripemd160 digests to allowedSignatureAlgorithms / allowedDigestAlgorithms and sets acceptPre5RootElementDigests; on the encryption side it sets allowRSA15KeyTransport, adds RSA-1.5 to allowedKeyAlgorithms, and adds LEGACY_DATA_ALGORITHMS — AES-CBC and TripleDES-CBC — to allowedDataAlgorithms; assigning any of these lists afterwards replaces it, so call enableLegacyMode() after configuring them). A previous null assignment still needs an edit, even if the next line calls enableLegacyMode(); for the standard legacy profile, remove the assignment and call it on the default configuration. That call enables several compatibility settings at once, so if only one additional algorithm is needed, widen just that list instead. See Migrating null algorithm allowlists. It does not undo the SignedInfo limits ($maxSignedInfoNodes, $maxSignedInfoNamespaces), the transforms verifyDocument() accepts, algorithm/key binding, uniform decrypt errors, decrypted-XML DOCTYPE rejection, Reference fail-closed behavior, SSRF rules, or the PHP/phpseclib requirements.
enableLegacyMode() does not restore decryption of an EncryptedData encrypted directly with RSA-1.5; see EncryptedData encrypted directly with RSA-1.5.
Migration tip: Prefer verifyDocument() with a pinned key. Use legacy mode only while updating peers.
Verifying a signature (recommended)
This example's protocol requires the verified Signature to be a direct child of Response.
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;
$doc = new DOMDocument();
$doc->load('./path/to/signed.xml');
// Pin the key/certificate you trust (do NOT read it from the document).
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type' => 'public'));
$objKey->loadKey('./path/to/trusted-cert.pem', true, true);
$objDSig = new XMLSecurityDSig();
// If assertions use custom Id attributes (e.g. WS-Security), declare them first:
// $objDSig->idKeys = array('wsu:Id');
// $objDSig->idNS = array('wsu' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd');
try {
// Throws on any failure; returns the validated nodes on success.
$validatedNodes = $objDSig->verifyDocument($objKey, $doc);
// The Signature that was verified. Read it before reusing $objDSig.
$signature = $objDSig->sigNode;
// Operate ONLY on $validatedNodes from here on.
// Each returned node is the reference target. For an enveloped
// signature, that node still contains the Signature element and
// its descendants (KeyInfo, Object, and so on). Check the
// expected element's name, namespace, and protocol-defined
// position, check that the verified Signature is where the
// protocol puts it, then read only the selected application
// children.
foreach ($validatedNodes as $node) {
if (! $node instanceof DOMElement
|| $node->localName !== 'Response'
|| $node->namespaceURI !== 'urn:example:app'
|| $node !== $doc->documentElement) {
throw new Exception('Unexpected signed element');
}
// Check the verified Signature's position before reading
// any assertion value.
if (! $signature instanceof DOMElement
|| $signature->localName !== 'Signature'
|| $signature->namespaceURI !== XMLSecurityDSig::XMLDSIGNS
|| $signature->parentNode !== $node) {
throw new Exception('Unexpected Signature position');
}
$assertions = array();
foreach ($node->childNodes as $child) {
if ($child instanceof DOMElement
&& $child->localName === 'Assertion'
&& $child->namespaceURI === 'urn:example:app') {
$assertions[] = $child;
}
}
// Read only the selected application children. Do not read
// $node->textContent or search descendants of $node; those
// also walk the Signature subtree.
foreach ($assertions as $assertion) {
$value = $assertion->textContent;
}
}
} catch (Exception $e) {
// Verification failed - reject the message.
}
Decrypting XML (recommended recipe)
xmlseclibs does not derive the decryption key from the document: you supply
your own private key, and the document's session key is unwrapped with it. The
recipe below covers the common EncryptedKey (key transport) + EncryptedData
(data) layout used by SAML and WS-Security, with the algorithm policy pinned.
use RobRichards\XMLSecLibs\XMLSecEnc;
use RobRichards\XMLSecLibs\XMLSecurityKey;
$doc = new DOMDocument();
$doc->load('./path/to/encrypted.xml');
$objenc = new XMLSecEnc();
// Pin the algorithm policy:
// - Key transport is restricted to RSA-OAEP by default
// ($objenc->allowedKeyAlgorithms === XMLSecEnc::DEFAULT_KEY_ALGORITHMS).
// - RSA-1.5 key transport is denied by default (Bleichenbacher); only
// enable it if you must interoperate with a legacy peer:
// $objenc->allowRSA15KeyTransport = true;
// $objenc->allowedKeyAlgorithms[] = XMLSecurityKey::RSA_1_5;
// - Symmetric data encryption (EncryptedData with an AES or 3DES
// EncryptionMethod) accepts AES-GCM by default
// ($objenc->allowedDataAlgorithms === XMLSecEnc::DEFAULT_DATA_ALGORITHMS).
// An EncryptedData encrypted directly with an RSA key-transport algorithm
// is governed by allowedKeyAlgorithms and allowRSA15KeyTransport, not
// allowedDataAlgorithms. AES-CBC and TripleDES-CBC, either:
// $objenc->enableLegacyMode();
// or, without also enabling RSA-1.5 key transport:
// $objenc->allowedDataAlgorithms = array_merge(
// XMLSecEnc::DEFAULT_DATA_ALGORITHMS,
// XMLSecEnc::LEGACY_DATA_ALGORITHMS
// );
$encData = $objenc->locateEncryptedData($doc);
if (! $encData) {
throw new Exception('Cannot locate EncryptedData');
}
$objenc->setNode($encData);
// Accept only the two types that decryptNode() parses as XML. With any
// other value, or no Type at all, decryptNode() returns the decrypted bytes
// as a string. To get the bytes, call decryptNode($objKey, false) instead.
$type = $encData->getAttribute('Type');
if ($type !== XMLSecEnc::Element && $type !== XMLSecEnc::Content) {
throw new Exception('Unexpected EncryptedData Type');
}
$objenc->type = $type;
// Resolve the session key. locateKey() reads the data algorithm from the
// document; locateKeyInfo() finds the EncryptedKey.
$objKey = $objenc->locateKey();
if (! $objKey) {
throw new Exception('Unknown data encryption algorithm');
}
if ($objKeyInfo = $objenc->locateKeyInfo($objKey)) {
if ($objKeyInfo->isEncrypted) {
// Load YOUR trusted private key to unwrap the session key.
$objKeyInfo->loadKey('./path/to/your-private-key.pem', true);
$sessionKey = $objKeyInfo->encryptedCtx->decryptKey($objKeyInfo);
$objKey->loadKey($sessionKey);
}
}
// If the session key was supplied out-of-band (no EncryptedKey), load it here:
// if (empty($objKey->key)) { $objKey->loadKey($sharedSecretBytes); }
// Decrypted content is returned; a DOCTYPE in the plaintext is rejected.
// A failure that depends on the ciphertext, including decrypted data that is
// not well-formed XML, throws an Exception with the message
// XMLSecurityKey::DECRYPTION_FAILURE and leaves $doc unchanged. Undoing a
// partial replacement uses the document's own DOM methods, so a registered
// node class that also refuses those calls can still leave $doc changed.
$decrypted = $objenc->decryptNode($objKey, true);
If the recipient key is selected by KeyName (rather than an embedded
EncryptedKey), read $objKeyInfo->name and load the matching local private
key yourself before decrypting. Never treat key material from the document as
trusted.
RSA-OAEP parameters and compatibility
locateKey() (including EncryptedKey resolution through locateKeyInfo())
reads OAEP parameters only from the selected encrypted element's direct
EncryptionMethod child. Following
XML Encryption 1.1 section 5.5.2:
- Both RSA-OAEP identifiers default to SHA-1 when
ds:DigestMethodis absent. RSA_OAEP(xmlenc11#rsa-oaep) defaults to MGF1-SHA1 whenxenc11:MGFis absent.RSA_OAEP_MGF1P(rsa-oaep-mgf1p) always uses MGF1-SHA1 and prohibits an MGF element.- Digest and MGF hashes are independent. Supported hashes are SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512, using their standard XML algorithm URIs.
xenc:OAEPparamsis a base64-encoded binary label; omission means an empty label. Invalid encodings, unsupported parameters and duplicate parameter elements throw.- An
xenc:KeySize, if present, must equal the RSA key modulus size in bits. It is accepted when it appears at most once and holds an xs:integer lexical form of a positive integer from 1 to 999999 (optional leading+, any leading zeros, surrounding whitespace). A mismatch fails decryption withFailure decrypting Data. When KeySize is absent, decryption is unchanged. Any other element in theEncryptionMethodis rejected.
Constructing XMLSecurityKey::RSA_OAEP yourself still selects
SHA-256/MGF1-SHA256, and constructing RSA_OAEP_MGF1P selects SHA-1/MGF1-SHA1.
These constructor defaults apply to decryption as well as encryption: they
are used whenever the key is not obtained from the document. A hand-built
RSA_OAEP private key passed to decryptKey() therefore expects SHA-256 and
cannot unwrap keys from senders that use the XML Encryption defaults
(SHA-1/MGF1-SHA1 with no DigestMethod/MGF), such as Shibboleth IdP.
For those senders either:
- resolve the key from the document with
locateKeyInfo()(orXMLSecurityKey::fromEncryptedKeyElement()), load your private key into the returned key, and call$key->encryptedCtx->decryptKey($key). The declared or default parameters are then applied; or - call
setOAEPParameters()on your hand-built key with the parameters you expect (no arguments selects the SHA-1/MGF1-SHA1 defaults).
To configure OAEP explicitly, before encryption or decryption:
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;
$key = new XMLSecurityKey(XMLSecurityKey::RSA_OAEP, array('type' => 'public'));
$key->setOAEPParameters(
XMLSecurityDSig::SHA256,
'http://www.w3.org/2009/xmlenc11#mgf1sha1',
'application-label' // Decoded bytes, not base64.
);
setOAEPParameters() with no arguments selects the specification defaults
(SHA-1/MGF1-SHA1, empty label). getOAEPParameters() returns the selected
digest and mgf URIs and decoded label, or null for non-OAEP keys.
These settings do not affect RSA-PSS signatures. encryptKey() and
encryptNode() serialize the parameters actually used, including explicit
SHA-256 declarations and any nonempty label.
Previously generated ciphertext: 4.0.0 through 4.0.2 could encrypt with
SHA-256/MGF1-SHA256 under xmlenc11#rsa-oaep while omitting the parameters.
That XML declares SHA-1 defaults and is nonconforming; it no longer decrypts
through specification-default key resolution. Regenerate it with explicit
parameters. For a controlled migration of known historical ciphertext only,
an application can explicitly configure the key with the known SHA-256
parameters using trusted out-of-band information. Do not rewrite incoming
signed XML or guess hashes by retrying decryption. There is no automatic
fallback; cryptographic failures retain the uniform Failure decrypting Data
message, and algorithm policies and RSA-1.5 restrictions remain in effect.
EncryptedData encrypted directly with RSA-1.5
An EncryptedData whose EncryptionMethod is RSA-1.5 and that has no
EncryptedKey holds the XML content itself as the RSA-1.5 plaintext. In 5.0
the built-in XMLSecurityKey does not decrypt it, in any mode:
- With RSA-1.5 not enabled,
decryptNode()throws the existing RSA-1.5 policy exception (RSA-1.5 key transport is disabled ...), as before. - With
allowRSA15KeyTransport = trueand RSA-1.5 inallowedKeyAlgorithms, or withenableLegacyMode(),decryptNode()throws an exception whose message starts withXMLSecurityKey::DIRECT_RSA15_DECRYPTION_UNSUPPORTED.enableLegacyMode()does not restore this read path. Every input that reaches the built-in direct RSA-1.5 decryption path gets the same capability error before key loading or RSA decryption. Malformed XML or a missing CipherValue can still fail earlier, and a provider override can handle the operation itself (see Existing documents below). - RSA-1.5
EncryptedKeydecryption and calls todecryptData()outsidedecryptNode()are not affected by this restriction. A correctly sized RSA-1.5 session key still decrypts withenableLegacyMode()or the explicit opt-in; for longer session keys, see Encrypted documents.
Senders: encrypt the XML content with AES-GCM and wrap the AES key with
RSA-OAEP in an EncryptedKey (encryptKey() with an XMLSecurityKey::RSA_OAEP
or RSA_OAEP_MGF1P key, then encryptNode() with the AES-GCM session key).
encryptNode() and encryptReferences() with an RSA-1.5 key require
$objenc->allowRSA15KeyTransport = true; (enableLegacyMode() sets it);
otherwise they throw an exception whose message starts with
XMLSecEnc::DIRECT_RSA15_ENCRYPTION_DISABLED before the template or the
document is changed. The opt-in is send-only compatibility for a peer that
requires this format, such as 3.1.x, during its migration: the built-in key
implementation cannot decrypt the result. encryptKey() is unchanged.
Existing documents: ask the sender to re-encrypt them in the format
above. If that is not possible, convert the archive in an isolated,
controlled process with a suitable provider-backed reader: an
XMLSecurityKey subclass that overrides decryptData() and performs the
RSA-1.5 decryption with a provider you have chosen for this purpose.
decryptNode() calls the override and uses its result; an override that
calls parent::decryptData() gets the exception above. Re-encrypt the
converted content in the format above, and do not use that reader for
incoming documents.
How to Install
Install with composer.phar.
php composer.phar require "robrichards/xmlseclibs"
Use cases
xmlseclibs is being used in many different software.
Basic usage
The example below shows basic usage of xmlseclibs, with a SHA-256 signature.
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;
// Load the XML to be signed
$doc = new DOMDocument();
$doc->load('./path/to/file/tobesigned.xml');
// Create a new Security object
$objDSig = new XMLSecurityDSig();
// Use the c14n exclusive canonicalization
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
// Sign the document element using SHA-256. The Reference points to it by
// its Id attribute, so verifyDocument() returns that DOMElement. With
// 'overwrite' => false an existing Id is kept; one is added if missing.
$objDSig->addReference(
$doc->documentElement,
XMLSecurityDSig::SHA256,
array('http://www.w3.org/2000/09/xmldsig#enveloped-signature'),
array('overwrite' => false)
);
// Create a new (private) Security key
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type'=>'private'));
/*
If key has a passphrase, set it using
$objKey->passphrase = '<passphrase>';
*/
// Load the private key
$objKey->loadKey('./path/to/privatekey.pem', TRUE);
// Sign the XML file
$objDSig->sign($objKey);
// Add the associated public key to the signature
$objDSig->add509Cert(file_get_contents('./path/to/file/mycert.pem'));
// Append the signature to the XML
$objDSig->appendSignature($doc->documentElement);
// Save the signed XML
$doc->save('./path/to/signed.xml');
How to Contribute
Mailing List: https://groups.google.com/forum/#!forum/xmlseclibs
관련 프로젝트 살펴보기
불러오는 중…