robrichards/xmlseclibs

Fatal Error

Closed this issue · 6 comments

Good afternoon, everyone,

I'm trying to sign an xml, using Rob's class, however I'm getting an error.
Fatal error: Uncaught Error: Class 'RobRichards\XMLSecLibs\XMLSecurityDSig' not found in C:\laragon\www\sgdl_2\teste2.php:12 Stack trace: #0 {main} thrown in C:\laragon\www\sgdl_2\teste2.php on line 12

Could someone help me solve it?

My code in attach.

Thanks.

`<?php

use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;

// Load the XML to be signed
$doc = new DOMDocument();

$doc->load('./teste.xml');

// Create a new Security object
$objDSig = new XMLSecurityDSig();
// Use the c14n exclusive canonicalization
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
// Sign using SHA-256
$objDSig->addReference(
$doc,
XMLSecurityDSig::SHA256,
array('http://www.w3.org/2000/09/xmldsig#enveloped-signature')
);

// Create a new (private) Security key
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type'=>'private'));

$objKey->passphrase = '';

// Load the private key
$objKey->loadKey('./iibcv.pfx', 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'));
$objDSig->add509Cert(file_get_contents('./SLL_IIB.pem'));

// Append the signature to the XML
$objDSig->appendSignature($doc->documentElement);
// Save the signed XML
$doc->save('./signed.xml');
//
?>`

This is not an issue with the library.. You probably fail to load the proper dependencies.

This is not an issue with the library.. You probably fail to load the proper dependencies.

I did all the installation of the dependencies, but even so I still have the same error.

Could you help me to solve it?

Thanks
image

It's kinda hard without knowing what you are doing exactly, but my best guess is that in teste4.php you forget to include the dependencies. Try adding include('vendor/autoload.php'); to the file.

It's kinda hard without knowing what you are doing exactly, but my best guess is that in teste4.php you forget to include the dependencies. Try adding include('vendor/autoload.php'); to the file.

What I need to do is sign the XML.

I already put in the code the dependency, and now I had another error.
Below the prints.

Thanks for your help.

image
image

Convert your pfx to pem