diff --git a/app/Services/EDocument/Standards/Verifactu/Signing/SigningService.php b/app/Services/EDocument/Standards/Verifactu/Signing/SigningService.php new file mode 100644 index 0000000000..6dbb2c4ae2 --- /dev/null +++ b/app/Services/EDocument/Standards/Verifactu/Signing/SigningService.php @@ -0,0 +1,45 @@ +loadXML($this->xml); + + $objDSig = new XMLSecurityDSig(); + $objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N); + $objDSig->addReference( + $doc, + XMLSecurityDSig::SHA256, + ['http://www.w3.org/2000/09/xmldsig#enveloped-signature'], + ['force_uri' => true] + ); + + $objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, ['type' => 'private']); + $objKey->loadKey($this->private_key, false); + + // Attach the certificate (public) to the KeyInfo + $objDSig->add509Cert($this->certificate, true, false, ['subjectName' => true]); + + $objDSig->sign($objKey); + $objDSig->appendSignature($doc->documentElement); + + // --- 3. Return signed XML as string --- + return $doc->saveXML(); + + } +} \ No newline at end of file