PHP code example of feimx / csd

1. Go to this page and download the library: Download feimx/csd 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/ */

    

feimx / csd example snippets



use JorgeAndrade\Csd;
use JorgeAndrade\Exceptions\CsdException;

$cer = getcwd() . "/csds/aad990814bp7_1210261233s.cer";
$key = getcwd() . "/csds/aad990814bp7_1210261233s.key";
$rfc = "AAD990814BP7";
$pass = "12345678a";

$validar = new Csd($cer, $key, $rfc, $pass, $path = getcwd() . "/csds/");

try {
    $validar->convertCerToPem();
    $validar->convertKeyToPem();

} catch (CsdException $e) {
    var_dump($e->getMessage());
}

composer 



use JorgeAndrade\Csd;
use JorgeAndrade\Exceptions\CsdException;

$cer = getcwd() . "/csds/aad990814bp7_1210261233s.cer";
$key = getcwd() . "/csds/aad990814bp7_1210261233s.key";
$rfc = "AAD990814BP7";
$pass = "12345678a"; //contraseña de la llave privada
$path = getcwd() . "/csds/"; //este parametro es opcional, por defecto usa **getcwd() . "/csds/"**

$validar = new Csd($cer, $key, $rfc, $pass, $path);

 $validar->convertCerToPem();

 $validar->convertKeyToPem();

 $periodo = $validar->verifyValidityPeriod();

 var_dump($periodo);

 /**
array(2) {
  ["fecha_inicial"]=>
  object(DateTime)#4 (3) {
    ["date"]=>
    string(26) "2012-10-26 19:22:43.000000"
    ["timezone_type"]=>
    int(2)
    ["timezone"]=>
    string(3) "GMT"
  }
  ["fecha_final"]=>
  object(DateTime)#5 (3) {
    ["date"]=>
    string(26) "2016-10-26 19:22:43.000000"
    ["timezone_type"]=>
    int(2)
    ["timezone"]=>
    string(3) "GMT"
  }
}
 **/

$validar->convertKeyToPem();
$validar->encryptPemInToDer($pass);

$check = $validar->verifyValidCsd(); //(bool)

$no_certificado = $validar->getNoCertificado();