EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Generete Digestvalue, x509Certificate and signaturevalue

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#6260
Posted: 05/14/2008 19:26:33
by Andresa Braz (Basic support level)
Joined: 05/08/2008
Posts: 5

Thanks Bogatskyy now it´s working correctly.
#6971
Posted: 07/17/2008 08:32:03
by Gabriel Herdt (Standard support level)
Joined: 04/09/2008
Posts: 37

Hi, I try compile my Function in New project delhphi and new computer. I sell my old computer. too old for work :D But in line:
Ref.URI := '#'+ FXMLDocument.DocumentElement.ChildNodes.Item[i].FindNode('infNFe').Attributes.GetNamedItem('Id').NodeValue;
I Have error: Access violation at address 008c2F57 in module sistema.exe read of address 0000000


Gabriel Herdt
Consystec
#6975
Posted: 07/17/2008 10:23:26
by Gabriel Herdt (Standard support level)
Joined: 04/09/2008
Posts: 37

somebody can help-me?

I have error: Access violation at address 008c2F57 in module sistema.exe read of address 0000000 in line : Ref.URI := '#'+ FXMLDocument.DocumentElement.ChildNodes.Item[i].FindNode('infNFe').Attributes.GetNamedItem('Id').NodeValue;


Gabriel Herdt
Consystec
#6976
Posted: 07/17/2008 10:29:48
by Ken Ivanov (EldoS Corp.)

I can just assume that either Item[i], FindNode('infNFe') or GetNamedItem('Id') returns nil, causing an AV. Please re-check that the corresponding elements are present in the document you are processing.

Dmytro will answer you in details as soon as possible.
#6979
Posted: 07/17/2008 11:17:03
by Dmytro Bogatskyy (EldoS Corp.)

Quote
I can just assume that either Item[i], FindNode('infNFe') or GetNamedItem('Id') returns nil, causing an AV

Yes. Also it is possible that DocumentElement returns null, in case of empty document.
#6980
Posted: 07/17/2008 12:37:25
by Gabriel Herdt (Standard support level)
Joined: 04/09/2008
Posts: 37

Value of FXMLDocument.DocumentElement.ChildNodes.Item[i].FindNode('INFNFE').OuterXML is > null


Gabriel Herdt
Consystec
#6981
Posted: 07/17/2008 12:44:50
by Gabriel Herdt (Standard support level)
Joined: 04/09/2008
Posts: 37

I need get atribute ID
FXMLDocument.DocumentElement.ChildNodes.Item[i].FindNode('INFNFE').OuterXML value is

Quote
'<INFNFE VERSAO="1.10" ID="NFE5108040388888800188885000000015555510000126515"> ... and more

...


Gabriel Herdt
Consystec
#6982
Posted: 07/17/2008 14:00:52
by Dmytro Bogatskyy (EldoS Corp.)

The problem is in "...FindNode('INFNFE').Attributes.GetNamedItem('Id')". It returns null because attribute names and other names in xml are case sensitive.
#9892
Posted: 05/03/2009 07:00:03
by Thanh Nguyen Trung (Priority Standard support level)
Joined: 09/12/2008
Posts: 73

void SignXML( byte[] data2Sign,
bool isXadesSignature,
XmlSignatureType signatureType,
string keyName,
bool isIncludeKey,
out byte[] signedData, out string errorCode)
{
errorCode = null;
signedData = null;

TElXMLDOMNode sigNode = null;
TElXAdESSigner xadesSigner = null;

TElXMLReference xmlReference = new TElXMLReference();
TElXMLReferenceList xmlReferenceLst = new TElXMLReferenceList();
TElXMLKeyInfoX509Data x509KeyData = new TElXMLKeyInfoX509Data(false);
TElXMLSigner xmlSigner = new TElXMLSigner();

try
{
if (m_cert != null)
{
string fname = Environment.TickCount.ToString() + ".xml";
fname = HttpRuntime.AppDomainAppPath + "tmp\\" + fname;
FileStream outputStream = new FileStream(fname, FileMode.Create, FileAccess.ReadWrite);
outputStream.Write(data2Sign, 0, data2Sign.Length);
outputStream.Position = 0;

TElXMLDOMDocument xmlDocument = new TElXMLDOMDocument();
xmlDocument.LoadFromStream(outputStream);

x509KeyData.Certificate = m_cert;
xmlSigner.KeyData = x509KeyData;

xmlReference.DigestMethod = SBXMLSec.Unit.xdmSHA1;
xmlReference.URINode = ((TElXMLDOMDocument)xmlDocument).DocumentElement;
xmlReference.URI = string.Empty;

xmlReference.TransformChain.Add(new TElXMLEnvelopedSignatureTransform());
xmlReferenceLst.Add(xmlReference);

switch (XADESOption.CanonicalizationMethod)
{
case XADESCanonicalizationMethod.Canon:
xmlSigner.CanonicalizationMethod = SBXMLDefs.Unit.xcmCanon;
break;
case XADESCanonicalizationMethod.CanonComment:
xmlSigner.CanonicalizationMethod = SBXMLDefs.Unit.xcmCanonComment;
break;
case XADESCanonicalizationMethod.MinCanon:
xmlSigner.CanonicalizationMethod = SBXMLDefs.Unit.xcmMinCanon;
break;
default:
xmlSigner.CanonicalizationMethod = SBXMLDefs.Unit.xcmCanon;
break;
}

xmlSigner.SignatureMethodType = SBXMLSec.Unit.xmtSig;
xmlSigner.SignatureMethod = SBXMLSec.Unit.xsmRSA_SHA1;
xmlSigner.MACMethod = SBXMLSec.Unit.xmmHMAC_SHA1;

xmlSigner.KeyName = keyName;
xmlSigner.IncludeKey = isIncludeKey;
xmlSigner.References = xmlReferenceLst;

switch (signatureType)
{
case XmlSignatureType.Detached:
xmlSigner.SignatureType = SBXMLSec.Unit.xstDetached;
break;
case XmlSignatureType.Enveloped:
xmlSigner.SignatureType = SBXMLSec.Unit.xstEnveloped;
break;
case XmlSignatureType.Enveloping:
xmlSigner.SignatureType = SBXMLSec.Unit.xstEnveloping;
break;
}

xmlSigner.OnFormatElement += new TSBXMLFormatElementEvent(FormatElement);
xmlSigner.OnFormatText += new TSBXMLFormatTextEvent(FormatText);

if (isXadesSignature && m_certStorage != null)
{

xadesSigner = new TElXAdESSigner();
xmlSigner.XAdESProcessor = xadesSigner;

switch (XADESOption.Version)
{
case XADESVersion.v1_1_1:
xadesSigner.XAdESVersion = SBXMLAdES.Unit.XAdES_v1_1_1;
break;
case XADESVersion.v1_2_2:
xadesSigner.XAdESVersion = SBXMLAdES.Unit.XAdES_v1_2_2;
break;
case XADESVersion.v1_3_2:
xadesSigner.XAdESVersion = SBXMLAdES.Unit.XAdES_v1_3_2;
break;
}

xadesSigner.PolicyId.SigPolicyId.Description = XADESOption.SigPolicyIdDescription;
xadesSigner.PolicyId.SigPolicyId.Identifier = XADESOption.SigPolicyIdIdentifier;

xadesSigner.PolicyId.SigPolicyId.IdentifierQualifier = SBXMLAdES.Unit.xqtNone;
if (!string.IsNullOrEmpty(XADESOption.SigPolicyIdIdentifier))
{
if (XADESOption.SigPolicyIdIdentifier.Substring(0, 4).ToLower() == "urn:")
xadesSigner.PolicyId.SigPolicyId.IdentifierQualifier = SBXMLAdES.Unit.xqtOIDAsURN;
else
xadesSigner.PolicyId.SigPolicyId.IdentifierQualifier = SBXMLAdES.Unit.xqtOIDAsURI;
}

if (XADESOption.IncludeProductionPlace)
{
xadesSigner.Included = SBXMLAdESIntf.Unit.xipProductionPlace;
xadesSigner.ProductionPlace.City = string.Empty;
xadesSigner.ProductionPlace.StateOrProvince = m_cert.SubjectName.StateOrProvince.ToString();
xadesSigner.ProductionPlace.PostalCode = string.Empty;
xadesSigner.ProductionPlace.CountryName = m_cert.SubjectName.Country.ToString();
}

if (TSPID > 0 && m_tspClient != null)
{
xadesSigner.TSPClient = m_tspClient;
xadesSigner.IgnoreTimestampFailure = false;
}

xadesSigner.SigningCertificates = m_certStorage;
xadesSigner.SigningTime = DateTime.Now.ToUniversalTime();

// create XAdESSigner.QualifyingProperties
xadesSigner.Generate();
xadesSigner.QualifyingProperties.XAdESPrefix = XADESOption.Prefix;
}

//Sign and Save
xmlSigner.UpdateReferencesDigest();
xmlSigner.Sign();
if (signatureType == XmlSignatureType.Detached)
{
xmlDocument.Dispose();
try
{
sigNode = null;
xmlSigner.Save(ref sigNode);
xmlDocument = sigNode.OwnerDocument;
}
catch
{
xmlDocument = new TElXMLDOMDocument();
}
}
else
{
sigNode = xmlDocument.OwnerDocument;
if (sigNode is TElXMLDOMDocument)
sigNode = ((TElXMLDOMDocument)sigNode).DocumentElement;
try
{
xmlSigner.Save(ref sigNode);
}
catch
{

}
}
signedData = xmlDocument.RawData;
outputStream.Close();
File.Delete(fname);
}
}
catch(Exception ex)
{
errorCode = ex.Message;
}
finally
{
if (xmlSigner != null)
xmlSigner.Dispose();
if (x509KeyData != null)
x509KeyData.Dispose();
if (xadesSigner != null)
xadesSigner.Dispose();
if (m_winCertStore != null)
m_winCertStore.SystemStores.EndUpdate();
}
}

Could you please take a look at my sample code, there exists an exception at xmlSigner.UpdateReferencesDigest(). Mesage is: "Transform chain returned no data"
#9893
Posted: 05/03/2009 08:57:10
by Thanh Nguyen Trung (Priority Standard support level)
Joined: 09/12/2008
Posts: 73

Hi.

I solved my problem.Thanks
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 61008 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!