marcelxyz / php-XmlDigitalSignature

Library for generating XML digital signatures in PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unabled to located the KeyValue node or it has no children

langaro opened this issue Β· comments

Hello, thanks for the library πŸ‘

Unfortunately I got this error:
Unabled to located the KeyValue node or it has no children

My code is:
`$dsig = new XmlDsig\XmlDigitalSignature();

$dsig->setCryptoAlgorithm(XmlDsig\XmlDigitalSignature::RSA_ALGORITHM)
->setDigestMethod(XmlDsig\XmlDigitalSignature::DIGEST_SHA512)
->forceStandalone();

try {
        $dsig->loadPrivateKey('certificados_gerados_github/private.pem', 'password');		
        $dsig->loadPublicKey('certificados_gerados_github/public.pem');
} catch (\UnexpectedValueException $e) {
        print_r($e);
        exit(1);
}

$fakeXml = new \DOMDocument();
$fakeXml->loadXML(file_get_contents(path to xml file'));

$node = $fakeXml->getElementsByTagName('InfDeclaracaoPrestacaoServico')->item(0);

try {
	$dsig->addObject($node, 'object', true);
	$dsig->sign();
	$dsig->verify();
} catch (\UnexpectedValueException $e) {
	print_r($e);
	exit(1);
}

var_dump($dsig->getSignedDocument());

`

Any clue?

Dear I also receive that error, which may be?