Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

signature_dfe

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

signature_dfe

  • 0.1.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

test Travis CI rubocop Gem Version

SignatureDfe

Assinatura digital de documentos fiscais eletrônicos (DF-e)

Descrição

Assine seu DF-e de forma rápida e fácil

Instalação

Add this line to your application's Gemfile:

gem 'signature_dfe'

And then execute:

$ bundle

Or install it yourself as:

$ gem install signature_dfe

Configurando

Você vai precisar do certificado PKCS12 ou da chave privada e o certificado público.

No caso de você ter o arquivo PKCS12

SignatureDfe::SSL.config.pkcs12   = "caminho/para/seu/cert.p12"
SignatureDfe::SSL.config.password = "sua_senha"

Já se vc usa a chave privada e o certificado separado

SignatureDfe::SSL.config.pkey      = "caminho/para/sua/chave_privada.pem"
SignatureDfe::SSL.config.password  = "sua_senha"
SignatureDfe::SSL.config.cert.     = "caminho/para/seu/certificado_publico.pem"

Feito esta configuração você testa, no caso de tudo certo, o resultado será true

SignatureDfe::SSL.test

Feito esta configuração vc já está pronto para assinar seus documentos.

Assinatura digital NF-e NFC-e e NFA-e

Observe que os 3 documentos possuem a mesma estrutura

Para assinar sua nf-e existem duas formas

A forma qual vc tem a xml da assinautra completo onde vc passa o seu xml contendo a tag infNFe

inf_nfe = %{
<infNFe Id="NFe00000000000000000000000000000000000000000000" versao="3.10">
  ...
</infNFe>}
SignatureDfe::NFe.sign inf_nfe

Onde a resposta será

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
  <SignedInfo>
    <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <Reference URI="#NFe...">
      <Transforms>
        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
        <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
      </Transforms>
      <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
      <DigestValue>...</DigestValue>
    </Reference>
  </SignedInfo>
  <SignatureValue>...</SignatureValue>
  <KeyInfo>
    <X509Data>
      <X509Certificate>...</X509Certificate>
    </X509Data>
  </KeyInfo>
</Signature>

E a forma qual onde você pode obter os valores do DigestValue, SignatureValue e X509Certificate manualmente, e assim montar da forma como desejar seu xml

inf_nfe = %{
<infNFe Id="NFe00000000000000000000000000000000000000000000" versao="3.10">
  ...
</infNFe>}
ch_nfe = "0000000000000000000000000000000000000000000"
digest_value = SignatureDfe::NFe.digest_value inf_nfe
signature_value = SignatureDfe::NFe.signature_value ch_nfe, digest_value
x509certificate = SignatureDfe::SSL.cert

Assinatura digital Evento de NF-e NFC-e e NFA-e

Observe que os 3 documentos possuem a mesma estrutura

Para assinar sua nf-e existem duas formas

A forma qual vc tem a xml da assinautra completo onde vc passa o seu xml contendo a tag infNFe

inf_evento = %{
<infEvento Id="ID1101115515151515151515151515156546546546545646544701">
  ...
</infEvento>
}
SignatureDfe::NFe::Event.sign inf_evento

Onde a resposta será

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
  <SignedInfo>
    <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <Reference URI="#ID1...">
      <Transforms>
        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
        <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
      </Transforms>
      <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
      <DigestValue>...</DigestValue>
    </Reference>
  </SignedInfo>
  <SignatureValue>...</SignatureValue>
  <KeyInfo>
    <X509Data>
      <X509Certificate>...</X509Certificate>
    </X509Data>
  </KeyInfo>
</Signature>

E a forma qual onde você pode obter os valores do DigestValue, SignatureValue e X509Certificate manualmente, e assim montar da forma como desejar seu xml

inf_evento = %{
<infEvento Id="ID1101115515151515151515151515156546546546545646544701">
  ...
</infEvento>}
event_id = "ID1101115515151515151515151515156546546546545646544701"
digest_value = SignatureDfe::NFe::Event.digest_value inf_evento
signature_value = SignatureDfe::NFe::Event.signature_value event_id, digest_value
x509certificate = SignatureDfe::SSL.cert

Assinatura digital de Inutilização

Segue-se exatamente como os documentos anteriores

Para assinar passo a passo

inf_inut = %{
  <infInut Id="ID06546541654654654654654654654654654654879">
  ...
  </infInut>
}
digest_value = SignatureDfe::Inutilizacao.digest_value inf_inut
inut_id = "ID06546541654654654654654654654654654654879"
signature_value = SignatureDfe::Inutilizacao.signature_value inut_id, digest_value
x509certificate = SignatureDfe::SSL.cert

Ou, para gerar toda a assinatura em único passo

inf_inut = %{
  <infInut Id="ID06546541654654654654654654654654654654879">
  ...
  </infInut>
}
SignatureDfe::Inutilizacao.sign inf_inut

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the SignatureDfe project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

FAQs

Package last updated on 24 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc