EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Repeating reference.

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#10893
Posted: 08/26/2009 08:02:12
by Gabriel Herdt (Standard support level)
Joined: 04/09/2008
Posts: 37

What can I do this (bold) not to happen?

- <Signature xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
- <SignedInfo>
...(Continued)


Signature function...

function TRDmConBas.Assinar2(Xml, sLote: WideString; iQtdNfe: Integer): WideString;
var
Signer: TElXMLSigner;
HMACKeyData: TElXMLKeyInfoHMACData;
RSAKeyData: TElXMLKeyInfoRSAData;
X509KeyData: TElXMLKeyInfoX509Data;
Cert: TElX509Certificate;
SigNode, Nodetest: TElXMLDOMNode;
Ref: TElXMLReference;
Refs: TElXMLReferenceList;
Elementos : ElXMLDOMElement;
Document : ElXMLDOMDocument;
S: WideString;
i,x : integer;
begin
inherited;
Try
i := 1;
x := iQtdNfe;


FXMLDocument := TElXMLDOMDocument.Create;
Elementos := ParseElementFromXMLString(Xml,FXMLDocument);
FXMLDocument.AppendChild(Elementos);

While i <= x do
Begin
Try
HMACKeyData := nil;
RSAKeyData := nil;
X509KeyData := nil;
Ref := nil;

Refs := TElXMLReferenceList.Create;
Ref := TElXMLReference.Create;
Ref.TransformChain.Add(TElXMLEnvelopedSignatureTransform.Create);
Ref.TransformChain.Add(TElXMLC14NTransform.Create);
Ref.URINode := FXMLDocument.DocumentElement.ChildNodes.Item[i].FindNode('infNFe');
Ref.URI := '#'+ FXMLDocument.DocumentElement.ChildNodes.Item[i].FindNode('infNFe').Attributes.GetNamedItem('Id').NodeValue;//Ref.URINode.Attributes.GetNamedItem('Id').NodeValue;
Refs.Add(Ref);

Signer := TElXMLSigner.Create(Self);

Try
Signer.SignatureType := xstEnveloped;
Signer.CanonicalizationMethod := xcmCanon;
Signer.SignatureMethodType := xmtSig;
Signer.SignatureMethod := xsmRSA_SHA1;
Signer.MACMethod := xmmHMAC_SHA1;
Signer.References := Refs;
Signer.IncludeKey := True;

ElWinCertStorage := TElWinCertStorage.Create(Owner);
ElWinCertStorage.SystemStores.Add('My');

Cert := ElWinCertStorage.Certificates[(NumeroCerti(OraDsNfeWebservDS_CERTIFICADO.Value)-1)];

if {Assigned(Cert) and} Cert.PrivateKeyExists then
begin
X509KeyData := TElXMLKeyInfoX509Data.Create(False);
X509KeyData.IncludeDataParams := [xkidX509Certificate, xkidX509CRL];
X509KeyData.IncludeKeyValue := False;
X509KeyData.Certificate := Cert;
Signer.KeyData := X509KeyData;
end;

Signer.UpdateReferencesDigest;

if True then
begin
Signer.Sign;
SigNode := FXMLDocument.DocumentElement.ChildNodes.Item[i];
if SigNode is TElXMLDOMDocument then begin
SigNode := TElXMLDOMDocument(SigNode).DocumentElement;
end;

try
Signer.Save(SigNode);
except
on E: Exception do
raise EElXMLError.CreateFmt('Falha ao salvar os dados da assinatura. (%s)', [E.Message]);
end;
end;
finally
FreeAndNil(Signer);
FreeAndNil(HMACKeyData);
FreeAndNil(RSAKeyData);
FreeAndNil(X509KeyData);
end;
finally
FreeAndNil(Refs);
end;
i := (i+1);
end;
SalvaArq(OraDsNfeWebServDS_CAMXML.AsString+IntToStr(Parametro.CD_EMPRES)+'-'+sLote+'env-lot.xml');

// MessageDlg('Lote Assinado com Sucesso!'+#10+OraDsNfeWebServDS_CAMXML.AsString+IntToStr(Parametro.CD_EMPRES)+'-'+sLote+'env-lot.xml', mtWarning, [mbOK], 0);
except
on E: Exception do
begin
MessageDlg('Ocorreu um ao gerar assinatura digital do lote de envio da nota fiscal: '+E.Message, mtError, [mbOk], 0);
Abort;
end;
end;
end;


Gabriel Herdt
Consystec
#10896
Posted: 08/26/2009 11:49:29
by Dmytro Bogatskyy (EldoS Corp.)

Quote
What can I do this (bold) not to happen?

- <Signature xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">

After Signer.Sign() method call please insert the following line:
Code
Signer.Signature.SignaturePrefix := '#default'

the default value is: '#default ds'
#10897
Posted: 08/26/2009 14:55:14
by Gabriel Herdt (Standard support level)
Joined: 04/09/2008
Posts: 37

Ok, thanks.


Gabriel Herdt
Consystec

Reply

Statistics

Topic viewed 959 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!