-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing an id in the tag #230
Comments
Try adding |
I tried adding the `$objDSig->addReference( );` Am I doing something wrong? |
I'm not sure this library is capable of what you want/need.. The ID-attribute is used in the ds:Reference URI-attribute so you know what element the signature belongs to.. Technically, if URI='', it means the signature belongs to the containing element.. This is defined in the dsig specifications.. I would have assumed that an empty URI would lead to not setting an ID.. I was wrong. |
I don't know if I was specific in my question, sorry about that. But the XML signed looks like this:
But I need it like this: You are basically saying that there is no way for me to remove the ID from the Alvara tag, correct? |
You were specific enough, it's clear to me what you want/need.... I'm just not sure if this library can do what you want.. |
Ok, thanks to trying to help. Even not solving the problem, you helped a lot. Thanks again. |
Hello everyone,
When I try to sign my XML file using the xmlseclibs, the library put an id with some kind of token on it, but the xsd schema for the xml don't allowed this. How can I fix this? I already tried to put the 'overwrite' => false in the addReference function and don't work. Can someone please help me?
Here is the code:
`$doc = new DOMDocument();
$doc->load('gerados/07-2021/arquivo_1_05_21.xml');
$Alvara = $doc->getElementsByTagName('Alvara')->item(0);
$Habitese = $doc->getElementsByTagName('Habitese')->item(0);
// Cria um objeto do tipo Security
$objDSig = new XMLSecurityDSig();
// Usa o c14n exclusive canonicalization
$objDSig->setCanonicalMethod(XMLSecurityDSig::C14N);
// Assina usando a criptografia
$objDSig->addReference(
$Alvara,
XMLSecurityDSig::SHA1,
array('http://www.w3.org/TR/2001/REC-xml-c14n-20010315'),
array('id_name' => '', 'overwrite' => false)
);
// Cria uma nova chave de segurança privada
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
/*
If key has a passphrase, set it using
$objKey->passphrase = '';
*/
// Carrega a chave privada do certificado
$objKey->loadKey('certificado/private.pem', TRUE);
// assina usando a chave privada
$objDSig->sign($objKey);
// Associa a chave publica na assinatura
$objDSig->add509Cert(file_get_contents('certificado/public.pem'));
// Escreve a assinatura na tag passada pelo parametro
$objDSig->appendSignature($Alvara);
// Salva o xml assinado
$doc->save('gerados/07-2021/assinado.xml');`
The text was updated successfully, but these errors were encountered: