» »

Davčna blagajna na androidu (Xamarin)

Davčna blagajna na androidu (Xamarin)

TadejGruber ::

Pozdravljeni.

Trenutno razvijam davčno blagajno na Androidu. Uporabljam pa Xamarin Studio (platforma Xamarin.Android).
Vem kako se v C# za desktop aplikacije naredi podpis XML dokumenta s certifikatom, vendar ta ista koda ne deluje na Androidu (Xamarinu).
SignedXml razreda mi sploh ne zazna, javlja pa mi napako "Can't implicitly conver System.Xml.XmlElement to System.XML.XmlElement" (verziji obeh knjižnic sta enaki).

Koda za podpis je takšna (če bo komu pomagala):

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument ();
xmlDoc.Load (filename);

// ------------že tukaj javi napako---------------------
System.Security.Cryptography.Xml.SignedXml signedXml = new System.Security.Cryptography.Xml.SignedXml (xmlDoc);
byte[] data = cert.GetPublicKey ();
string base64 = Convert.ToBase64String (data);

RSACryptoServiceProvider rsaCSP = (RSACryptoServiceProvider)cert.PrivateKey;

CspParameters cspParameters = new CspParameters ();
cspParameters.KeyContainerName = rsaCSP.CspKeyContainerInfo.KeyContainerName;
cspParameters.KeyNumber = rsaCSP.CspKeyContainerInfo.KeyNumber == KeyNumber.Exchange ? 1 : 2;

RSACryptoServiceProvider rsaAesCSP = new RSACryptoServiceProvider (cspParameters);
signedXml.SigningKey = rsaAesCSP; //newKey;

System.Security.Cryptography.Xml.KeyInfo keyInfo = new System.Security.Cryptography.Xml.KeyInfo ();
System.Security.Cryptography.Xml.KeyInfoX509Data keyInfoData = new System.Security.Cryptography.Xml.KeyInfoX509Data ();
keyInfoData.AddIssuerSerial (cert.Issuer, cert.SerialNumber);
X509Extension extension = cert.Extensions [1];
AsnEncodedData asndata = new AsnEncodedData (extension.Oid, extension.RawData);
keyInfoData.AddSubjectName (cert.SubjectName.Name);

System.Security.Cryptography.Xml.Reference reference = new System.Security.Cryptography.Xml.Reference ();
reference.Uri = "#test";
reference.DigestMethod = @"http://www.w3.org/2001/04/xmlenc#sha256";

System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform env = new System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform ();
reference.AddTransform (env);

signedXml.AddReference (reference);
keyInfo.AddClause (keyInfoData);

signedXml.KeyInfo = keyInfo;
signedXml.SignedInfo.SignatureMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";

signedXml.ComputeSignature ();
System.Xml.XmlElement xmlDigitalSignature = (System.Xml.XmlElement)signedXml.GetXml ();

XmlNode element = xmlDoc.GetElementsByTagName ("fu:InvoiceRequest") [0];
element.AppendChild (xmlDigitalSignature);


Če kdorkoli ve kaj delam narobe ali morda za kakšen drug način kako zgenerirati podpis Xml datoteke (niza), se priporočam za vso pomoč, ki jo lahko dobim.

Tadej Gruber

stb ::

Še enkrat preberi sporočilo o napaki:
"Can't implicitly conver System.Xml.XmlElement to System.XML.XmlElement"

TadejGruber ::

stb je izjavil:

Še enkrat preberi sporočilo o napaki:
"Can't implicitly conver System.Xml.XmlElement to System.XML.XmlElement"


Se opravičujem, to sem jaz tiskarsko napako naredil, ko sem tipkal.

Zgodovina sprememb…



Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Davčne blagajne (strani: 1 2 3 424 25 26 27 )

Oddelek: Programiranje
1344334581 (74584) Macketina
»

E-račun

Oddelek: Programiranje
217544 (4307) ivanhoe5x
»

PHP davčna blagajna

Oddelek: Programiranje
188156 (6180) brble
»

[JAVA] HTTPS client

Oddelek: Programiranje
173193 (1923) peterv6i
»

C# - xml import v bazo

Oddelek: Programiranje
71485 (1303) nuclear

Več podobnih tem