1.0.0 • Published 4 years ago

firmafiel v1.0.0

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
4 years ago

Api de Firmado electronico PKI

Se puede implementar desde el browser o desde el servidor

Installing

$ npm install firmafiel

Stages

  1. verificación del certificado via OCSP
  2. firmado desde el navegador
  3. validacion de cadenas firmadas

Ejemplo:

var firmafiel = require("firmafiel");
var fs = require("fs");

var privateKey = fs.readFileSync("PRIVATEKEY.key");
var publicKey = fs.readFileSync("PUBLICKEY.cer");

test = async () => {
  //convertir el archivo a formato PEM
  const pemPublicKey = firmafiel.cerbuffertopem({ derBuffer: publicKey });
  //verifica el certificado
  var prueba = await firmafiel.verificarCertificado({
    certificado: pemPublicKey
  });

  var rfc = "XXXXXXXXXXXXX"; //rfc
  var password = "secret"; //contraseña de la llave privada
  var cadena = "Test String"; // cadena a firmar
  var firma = null; //donde quedara la firma

  const pemPrivateKey = firmafiel.keybuffertopem({ derBuffer: privateKey });

  if (
    prueba.data.status === "good" && //good revoked unknown
    firmafiel.validarfcfrompem({ pem: pemPublicKey, rfc: rfc })
  ) {
    firma = firmafiel.firmarCadena({
      pempublica: pemPublicKey,
      pemprivada: pemPrivateKey,
      passprivada: password,
      cadena: cadena
    });

    console.log(firma);
  }
  var valid = firmafiel.verificarFirma({
    pempublica: pem,
    cadena: "PRUEBA",
    pemfirma: cadenafirmada
  });

  console.log(valid); //true | false
};

test();

LICENSE

MIT License

Copyright (c) 2019 Luis Lucio

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.