Skip to content

Instantly share code, notes, and snippets.

@diegorocha
Created June 12, 2015 15:58
Show Gist options
  • Save diegorocha/d72cdec5f6f7f523e463 to your computer and use it in GitHub Desktop.
Save diegorocha/d72cdec5f6f7f523e463 to your computer and use it in GitHub Desktop.
function TFormPrincipal.Assinar(pArquivoXML, pTagAssinar: String): Boolean;
var
Fentrada:File;
NumRead,i, resultado:integer;
buf: char;
S: string;
Util: OleVariant;
XMLString, tagAssinatura, Atributo, XMLAssinado, msgResultado: Widestring;
SL: TStringList;
begin
SL := TStringList.Create;
AssignFile(Fentrada,pArquivoXML);
Reset(Fentrada,1);
S:='';
for i:= 1 to FileSize(Fentrada) do
begin
Blockread(Fentrada,buf,1,NumRead);
S:=S+buf;
end;
CloseFile(Fentrada);
SL.Text := S;
XMLString := S;
tagAssinatura := pTagAssinar; // indica a tag a ser assinada (RPS), para assinar lote altere para LoteRps
Atributo := 'Id'; // indica o aributo que será utilizado como Id
msgResultado := '';
// instancia a DLL
Util := CreateOleObject('NFSe_Util.util');
// assinar
XMLAssinado := Util.Assinar(XMLString,tagAssinatura,Atributo, G_IdDigital, resultado, msgResultado);
SL.Text := XMLAssinado;
SL.SaveToFile(pArquivoXML);
SL.Free;
result := (resultado = 5300)
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment