Henry00jj95
Seguir
- Seguidores
- 5
Zeta
Verificado
Verificación en dos pasos activada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Verificado por Binance
¡Usuario popular!
- Desde
- 29 May 2019
- Mensajes
- 1.797
buenas noches betas, estoy buscando a una persona que me ayude con mi sistema para la firma electronica
ya tengo bastante avanzado el proyecto pero en la parte de firmar el documento para enviar al SRI no he avanzado estoy con problemas
si alguien tiene conocimiento escribame para llegar a un acuerdo
ya tengo el archivo .p12 y su respectiva clave pero no he logrado hacerle funcionar, el sistema lo tengo en PHP
he estado intentando con esto pero lo logro hacerle funcionar.
ya tengo bastante avanzado el proyecto pero en la parte de firmar el documento para enviar al SRI no he avanzado estoy con problemas
si alguien tiene conocimiento escribame para llegar a un acuerdo
ya tengo el archivo .p12 y su respectiva clave pero no he logrado hacerle funcionar, el sistema lo tengo en PHP
PHP:
<?php
require_once 'vendor/autoload.php';
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;
class XMLSigner
{
private $certificatePath;
private $password;
public function __construct($certificatePath, $password)
{
$this->certificatePath = $certificatePath;
$this->password = $password;
}
public function signXML($xmlPath)
{
// Cargar el XML
$xml = new DOMDocument();
$xml->load($xmlPath);
// Extraer certificado y llave privada del P12
$p12 = file_get_contents($this->certificatePath);
$certInfo = [];
if (! openssl_pkcs12_read($p12, $certInfo, $this->password)) {
throw new Exception('No se pudo leer el certificado P12');
}
// Crear instancia de firma
$objDSig = new XMLSecurityDSig();
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
// Agregar la referencia al documento
$objDSig->addReference(
$xml,
XMLSecurityDSig::SHA256,
['http://www.w3.org/2000/09/xmldsig#enveloped-signature'],
['force_uri' => true]
);
// Crear una nueva llave de seguridad
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, ['type' => 'private']);
$objKey->loadKey($certInfo['pkey']);
// Insertar la firma
$objDSig->sign($objKey);
// Agregar la llave pública al documento
$objDSig->add509Cert($certInfo['cert']);
// Guardar el XML firmado
$signedXmlPath = str_replace('.xml', '_signed.xml', $xmlPath);
$xml->save($signedXmlPath);
return $signedXmlPath;
}
}
// Uso
try {
$signer = new XMLSigner('archivo.p12', 'password123');
$signedFile = $signer->signXML('test.xml');
echo "XML firmado correctamente. Archivo guardado como: " . $signedFile;
} catch (Exception $e) {
echo "Error al firmar: " . $e->getMessage();
}
he estado intentando con esto pero lo logro hacerle funcionar.