ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Como firmar documentos XML usando XMLDSig


Enviado por   •  26 de Julio de 2022  •  Tutoriales  •  422 Palabras (2 Páginas)  •  102 Visitas

Página 1 de 2

Cómo firmar documentos XML usando XMLDSig (Firma XML)

Crear documento

<?xml version="1.0" encoding="UTF-8"?>

<document>

  <hello>All XML is doomed to fail.</hello>

  <!-- Signature contains the signature definition -->

  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">

    <SignedInfo>

      <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>

      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>

      <Reference>

        <Transforms>

          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>

          <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>

        </Transforms>

        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>

        <DigestValue />

      </Reference>

      </SignedInfo>

    <SignatureValue />

    <KeyInfo>

      <X509Data />

    </KeyInfo>

  </Signature>

</document>

Firmar documento

xmlsec1 --sign --privkey-pem xxx.com.key,xxx.com.cer --output signed.xml tosign.xml

 

Verificar documento

xmlsec1 --verify --trusted-pem vrkthsp.pem --trusted-pem vrktestc.pem signed.xml

Tenga en cuenta que un archivo PEM concatenado, es decir, cat vrkthsp.pem vrktestc.pem > concat.pem, no funciona con xmlsec1.

Cómo especificar qué elementos firmar con ds:Reference

Agregue uno o más elementos ds:Reference para especificar qué elementos se deben firmar. Cada elemento debe tener una ID única en el atributo URI. La ID debe tener un prefijo con un hash, por ejemplo, #your-id :

<ds:Reference URI="#secret-xml-sauce">

Asegúrese de que su documento contenga un elemento que tenga la ID exacta sin el prefijo hash:

<Dog ID="secret-xml-sauce" name="Christian" />

Luego, use el interruptor “—id-attr” para especificar el elemento y el nombre del atributo:

xmlsec1 --sign --privkey-pem signing.key,signing.pem --id-attr:ID Dog --id-attr:ID structuredBody --output signed.xml tosign.xml

Tenga en cuenta que "id" es el nombre de atributo predeterminado. Solo necesita el interruptor —id-attr si tiene la ID en un atributo que tiene un nombre diferente.

Cómo firmar varios elementos

Simplemente agregue otro “—id-attr: " cambiar:

xmlsec1 --sign --privkey-pem signing.key,signing.pem --id-attr:ID signatureTimestamp --id-attr:ID structuredBody --output signed.xml tosign.xml

Luego agregue otro elemento que tenga la ID dada.

...

Descargar como (para miembros actualizados)  txt (3.3 Kb)   pdf (65 Kb)   docx (9.2 Kb)  
Leer 1 página más »
Disponible sólo en Clubensayos.com