public string upgradeToEST(String signedEReceteFilePath) { LisansHelper.loadLicense(); String retSignedXmlPath = null; try { //create context with working dir string currentDirectory = Directory.GetCurrentDirectory(); Context context = new Context(currentDirectory); XMLSignature signature = XMLSignature.parse(new FileDocument(new FileInfo(signedEReceteFilePath)), context); signature.upgradeToXAdES_T(); FileInfo sourceFileInfo = new FileInfo(signedEReceteFilePath); string destDirPath = sourceFileInfo.Directory.FullName; retSignedXmlPath = destDirPath + "/" + sourceFileInfo.Name.Replace(".xsig", "_EST.xsig"); FileStream signatureFileStream = new FileStream(retSignedXmlPath, FileMode.Create); signature.write(signatureFileStream); signatureFileStream.Close(); } catch (XMLSignatureException exc) { // cant create signature MesajiIsle("Hata Oluştu." + exc.Message, 1); } catch (Exception exc) { // probably couldn't write to the file MesajiIsle("Hata Oluştu." + exc.Message, 1); } return(retSignedXmlPath); }
public string createParalelSignature(string eReceteSourceFilePath) { string retSignedXmlPath = null; //Load license from file //LisansHelper.loadFreeLicenseBase64(); LisansHelper.loadLicense(); try { // create context with working dir string currentDirectory = Directory.GetCurrentDirectory(); Context context = new Context(currentDirectory); SignedDocument signatures = new SignedDocument(context); //First Signature XMLSignature signature1 = signatures.createSignature(); signature1.SigningTime = DateTime.Now; signature1.addDocument(eReceteSourceFilePath, null, true); KeyOrSmartCardSignManager keyOrSmartCardSignManager = KeyOrSmartCardSignManager.Instance; ECertificate signingCert = keyOrSmartCardSignManager.getSigningCertificate(); bool validCertificate = isValidCertificate(signingCert); if (!validCertificate) { MesajiIsle("İmza atılmak istenen sertifika geçerli değil." + Program.HataMesaji, 1); return(null); } // add certificate to show who signed the document signature1.addKeyInfo(signingCert); BaseSigner smartCardSigner = keyOrSmartCardSignManager.getSigner(signingCert); signature1.sign(smartCardSigner); //Second Signature XMLSignature signature2 = signatures.createSignature(); signature2.SigningTime = DateTime.Now; signature2.addDocument(eReceteSourceFilePath, null, true); signature2.addKeyInfo(signingCert); signature2.sign(smartCardSigner); FileInfo sourceFileInfo = new FileInfo(eReceteSourceFilePath); string destDirPath = sourceFileInfo.Directory.FullName; retSignedXmlPath = destDirPath + "/" + sourceFileInfo.Name.Replace(".xml", "_PARALEL.xsig"); FileStream signatureFileStream = new FileStream(retSignedXmlPath, FileMode.Create); signatures.write(signatureFileStream); signatureFileStream.Close(); return(retSignedXmlPath); } catch (XMLSignatureException exc) { // cant create signature MesajiIsle("Hata Oluştu." + exc.Message, 1); } catch (Exception exc) { // probably couldn't write to the file MesajiIsle("Hata Oluştu." + exc.Message, 1); } return(retSignedXmlPath); }
public string addSerialSignature(String signedEReceteFilePath) { LisansHelper.loadLicense(); String retSignedXmlPath = null; try { //create context with working dir string currentDirectory = Directory.GetCurrentDirectory(); Context context = new Context(currentDirectory); XMLSignature signature = XMLSignature.parse(new FileDocument(new FileInfo(signedEReceteFilePath)), context); // create counter signature XMLSignature counterSignature = signature.createCounterSignature(); counterSignature.SigningTime = DateTime.Now; // sign // add certificate to show who signed the document KeyOrSmartCardSignManager keyOrSmartCardSignManager = KeyOrSmartCardSignManager.Instance; ECertificate signingCert = keyOrSmartCardSignManager.getSigningCertificate(); counterSignature.addKeyInfo(signingCert); // now sign it by using smart card // now sign it BaseSigner baseSigner = keyOrSmartCardSignManager.getSigner(signingCert); counterSignature.sign(baseSigner); FileInfo sourceFileInfo = new FileInfo(signedEReceteFilePath); string destDirPath = sourceFileInfo.Directory.FullName; retSignedXmlPath = destDirPath + "/" + sourceFileInfo.Name.Replace(".xsig", "_Counter.xsig"); FileStream signatureFileStream = new FileStream(retSignedXmlPath, FileMode.Create); signature.write(signatureFileStream); signatureFileStream.Close(); } catch (XMLSignatureException exc) { // cant create signature MesajiIsle("Hata Oluştu." + exc.Message, 1); } catch (Exception exc) { // probably couldn't write to the file MesajiIsle("Hata Oluştu." + exc.Message, 1); } return(retSignedXmlPath); }
private void tmrGiris_Tick(object sender, EventArgs e) { //if (Program.himm == 1) //{ // Application.Exit(); //} tmrGiris.Enabled = false; // LisansHelper.loadFreeLicense(); LisansHelper.loadLicense(); if (Program.ParamSlotID == "") { if (KartveOkuyucuKontrol() == false) { Environment.Exit(1); } } if (Program.ParamOto == "1") { btnEReceteImzala_Click(btnEReceteImzala, new EventArgs()); } ; }