I have tried many times and many ways to get the xadesSignedProperties encoded hash (DigestValue) but always I get uncorrect result . I have this singed properties :
<xades:SignedProperties Id="xadesSignedProperties">
<xades:SignedSignatureProperties>
<xades:SigningTime>2023-07-17T18:22:23Z</xades:SigningTime>
<xades:SigningCertificate>
<xades:Cert>
<xades:CertDigest>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>ZDE1MzZmNzFhOGNjZTc2ZjIzMWEwZTg4ZWY0MzlkNGQwMThkOWQ2MjQ2ZTdkNWM5YTczMjlhNzA4MjJlMWVhMw==</ds:DigestValue>
</xades:CertDigest>
<xades:IssuerSerial>
<ds:X509IssuerName>O=Alamal For Gold and Jewellery, OU=HEAD-OFFICE, C=SA, CN=ALAMAL</ds:X509IssuerName>
<ds:X509SerialNumber>408202254781608792003747220510677813404473504788</ds:X509SerialNumber>
</xades:IssuerSerial>
</xades:Cert>
</xades:SigningCertificate>
</xades:SignedSignatureProperties>
</xades:SignedProperties>
I followed the steps in the documentation :
But I always get the wrong digest value . The digest value of the previous signed propeties should be
MzBkOWYwMDc0ZGNhMWE2YzA0NDVlZWJmYTc5NmUwYTM1M2Q5NjhiMjMwNDc2YmJjNGJhYWM2ZDQ3NjYwNzU3YQ==
as it is shown in this xadesSignedProperties block :
<ds:Reference Type="http://www.w3.org/2000/09/xmldsig#SignatureProperties" URI="#xadesSignedProperties">
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>MzBkOWYwMDc0ZGNhMWE2YzA0NDVlZWJmYTc5NmUwYTM1M2Q5NjhiMjMwNDc2YmJjNGJhYWM2ZDQ3NjYwNzU3YQ==</ds:DigestValue>
</ds:Reference>
I Looked to these answers but also I couldn't get the correct digest value .
How to compute the digest for the SignedProperties of a XAdES signature?
how can i hash a specific tag from XML file in a correct way?
This is one of my tries :
$populateSignedPropertiesOutputXML = new DOMDocument(encoding: 'utf-8');
$populateSignedPropertiesOutputXML->loadXML(str_replace("\r", "", $signedPropertiesBlock));
$populatedSignedPropertiesString = $populateSignedPropertiesOutputXML->C14N();
$populatedSignedPropertiesString = unpack('H*', $populatedSignedPropertiesString)['1'];
$hashedSignedProperties = hash('sha256', $populatedSignedPropertiesString);
return base64_encode($hashedSignedProperties);