PHP code example of edwinjuarezpe / cr-mh-sign
1. Go to this page and download the library: Download edwinjuarezpe/cr-mh-sign library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
edwinjuarezpe / cr-mh-sign example snippets
EdwinJuarez\Mh\Facade\MhSigner;
use EdwinJuarez\Mh\Signing\Algorithm;
$certPath = __DIR__ . '/examples/cert/mi-certificado.p12';
$certPassword = 'mi_password';
$unsignedXmlPath = __DIR__ . '/examples/xml_unsigned/mi_comprobante.xml';
$signedXmlPath = __DIR__ . '/examples/xml_signed/mi_comprobante.xml';
$signer = MhSigner::fromP12($certPath, $certPassword);
$signed = $signer->signXmlFile($unsignedXmlPath);
file_put_contents($signedXmlPath, rtrim($signed, PHP_EOL));
echo "OK: firmado en $signedXmlPath", PHP_EOL;
EdwinJuarez\Mh\Facade\MhSigner;
use EdwinJuarez\Mh\Signing\Algorithm;
$certPath = __DIR__ . '/examples/cert/mi-certificado.p12';
$certPassword = 'mi_password';
$xmlString = file_get_contents(__DIR__ . '/examples/xml_unsigned/mi_comprobante.xml');
$signer = MhSigner::fromP12($certPath, $certPassword);
$signed = $signer->signXmlString($xmlString);
echo $signed; // o guardar con file_put_contents(...)