DigestValue in XML signature in java is different from PHP

This is the digest value that it was calculated in java

SF4D6+PX7VB2hDbnb59a4WrWMOk=

This is the digest value that I have calculated with

    $nodoDocumento = $doc3
        ->getElementsByTagName('factura')
        ->item(0);
    $content = $nodoDocumento->C14N(FALSE, TRUE);
    // OR
    $content = $nodoDocumento->C14N(TRUE, TRUE);
    $actualDigest = base64_encode(hash('SHA1', $content, false));

gave me

NDg1ZTAzZWJlM2Q3ZWQ1MDc2ODQzNmU3NmY5ZjVhZTE2YWQ2MzBlOQ==

and this is my xml file

<?xml version="1.0" encoding="UTF-8"?>
<factura id="comprobante" version="1.0.0">
<infoTributaria>
    <ambiente>1</ambiente>
    <tipoEmision>1</tipoEmision>
    <razonSocial>Carrillo Serrano Juan Roberto</razonSocial>
    <nombreComercial>Carrillos Team</nombreComercial>
    <ruc>1703644805001</ruc>
    <claveAcceso>2710201401170364480500110010010000000011234567812</claveAcceso>
    <codDoc>01</codDoc>
    <estab>001</estab>
    <ptoEmi>001</ptoEmi>
    <secuencial>000000001</secuencial>
    <dirMatriz>La Condamine N16-37 y Solano </dirMatriz>
</infoTributaria>
<infoFactura>
    <fechaEmision>27/10/2014</fechaEmision>
    <dirEstablecimiento>La Condamine N16-37 y Solano</dirEstablecimiento>
    <obligadoContabilidad>NO</obligadoContabilidad>
    <tipoIdentificacionComprador>04</tipoIdentificacionComprador>
    <razonSocialComprador>SALGRAF CIA. LTDA</razonSocialComprador>
    <identificacionComprador>1792067464001</identificacionComprador>
    <totalSinImpuestos>3500.00</totalSinImpuestos>
    <totalDescuento>0.00</totalDescuento>
    <totalConImpuestos>
        <totalImpuesto>
            <codigo>2</codigo>
            <codigoPorcentaje>2</codigoPorcentaje>
            <baseImponible>3500.00</baseImponible>
            <valor>420.00</valor>
        </totalImpuesto>
    </totalConImpuestos>
    <propina>0.00</propina>
    <importeTotal>3920.00</importeTotal>
    <moneda>DOLAR</moneda>
</infoFactura>
<detalles>
    <detalle>
        <codigoPrincipal>001</codigoPrincipal>
        <descripcion>DESARROLLO DE SOFTWARE</descripcion>
        <cantidad>1</cantidad>
        <precioUnitario>3500</precioUnitario>
        <descuento>0</descuento>
        <precioTotalSinImpuesto>3500.00</precioTotalSinImpuesto>
        <impuestos>
            <impuesto>
                <codigo>2</codigo>
                <codigoPorcentaje>2</codigoPorcentaje>
                <tarifa>12.00</tarifa>
                <baseImponible>3500.00</baseImponible>
                <valor>420.00</valor>
            </impuesto>
        </impuestos>
    </detalle>
</detalles>
<infoAdicional>
    <campoAdicional nombre="Dirección">Los Eucaliptos E1-374 y Av. 10 de Agosto    
    </campoAdicional>
    <campoAdicional nombre="Teléfono">2471233 ext. 101</campoAdicional>
    <campoAdicional nombre="Email">[email protected]</campoAdicional>
</infoAdicional>
</factura>`

Upvotes: 0

Views: 562

Answers (1)

Stefan Gehrig
Stefan Gehrig

Reputation: 83612

Try

$actualDigest = base64_encode(hash('SHA1', $content, true));

The third parameter $raw_output controls whether the return value is the raw binary value or a string of lowercase hexits. If you need a base64-encoded SHA1 you need to base64-encode the raw binary value instead of the hexadecimal representation of that binary value.

Upvotes: 1

Related Questions