private void Button_Click_1(object sender, RoutedEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } opensslkeycsharp libssl = new opensslkeycsharp(); string cadenaOriginal = "161200302222|Renovación de Certificado Digital|26-12-2016 12:59:57|MAHA7710074X8|ALBERTO AUGUSTO MANZANILLA HERNANDEZ | 00001000000404657715 / 00001000000203446715 | MIIBCgKCAQEAtsht8BjqegtDjgwdn38RtvZsGNyzZOd6mU / nj4W5F1JaDj + KCEdVkBVQ2PNhyQt8JbuOEPS0gHVHLG2QbBEEilYHYNSUeomPpm0dg2RLVr / 1NMsXH2rVYBW2SfMdo + pu70m5 +/ JO1naBnOksJXkjgfAeQe9rHyCy84vKSxengQ8ECmrr7ZT6azmfm"; //string hardcodeFileRoute = @"D:\tempfolder\FIEL_MAHA7710074X8_20130412103407\Renovacion2017\Renovacion_FIEL_MAHA7710074X8_20161226130030\00001000000404657715.cer"; string hardcodeFileRoute = @"C:\Users\alber\OneDrive\Documentos\ReunionesVarias.txt"; FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Read, @txtCertRoute.Text); permission.Assert(); string localFolder = ApplicationData.Current.LocalFolder.DisplayName; string roamingfolder = ApplicationData.Current.RoamingFolder.DisplayName; try { Stream s = File.OpenRead(txtCertRoute.Text); } catch (Exception ex) { resultXmlText.Text = ex.Message + " : " + ex.StackTrace; Console.WriteLine(ex.StackTrace); return; } if (File.Exists(hardcodeFileRoute)) { Console.Write("found file..."); } else { resultXmlText.Text = "cannot open file, no acces? or non existen file"; return; } if (txtCertRoute.Text != string.Empty && txtCertRoute.Text != "ruta al .cer" && txtKeyRoute.Text != string.Empty && txtKeyRoute.Text != "ruta al .key") { if (File.Exists(txtCertRoute.Text)) { Console.Write("File exists"); } string signedString = libssl.SignString(@txtKeyRoute.Text, "..L3oyS4m..", cadenaOriginal); string Certificate = string.Empty; string CertificateNumber = string.Empty; libssl.CertificateData(@txtCertRoute.Text, out Certificate, out CertificateNumber); resultXmlText.Text = "Certificate data: " + Certificate + " | Certificate number: " + CertificateNumber; return; } }
private void signBtn_Click(object sender, RoutedEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } opensslkeycsharp libssl = new opensslkeycsharp(); //string cadenaOriginal = "161200302222|Renovación de Certificado Digital|26-12-2016 12:59:57|MAHA7710074X8|ALBERTO AUGUSTO MANZANILLA HERNANDEZ | 00001000000404657715 / 00001000000203446715 | MIIBCgKCAQEAtsht8BjqegtDjgwdn38RtvZsGNyzZOd6mU / nj4W5F1JaDj + KCEdVkBVQ2PNhyQt8JbuOEPS0gHVHLG2QbBEEilYHYNSUeomPpm0dg2RLVr / 1NMsXH2rVYBW2SfMdo + pu70m5 +/ JO1naBnOksJXkjgfAeQe9rHyCy84vKSxengQ8ECmrr7ZT6azmfm"; string cadenaOriginal = "<xlm><node1>Alberto Manzanilla</node1></xml>"; FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Read, txtCerPath.Text); permission.Assert(); try { Stream s = File.OpenRead(txtCerPath.Text); } catch (Exception ex) { txtResultMessages.Text = ex.Message + " : " + ex.StackTrace; Console.WriteLine(ex.StackTrace); return; } if (txtCerPath.Text != string.Empty && txtCerPath.Text != "Ruta al .cer" && txtKeyPath.Text != string.Empty && txtKeyPath.Text != "Ruta al .key") { if (File.Exists(txtCerPath.Text)) { Console.Write("File exists"); } string Certificate = string.Empty; string CertificateNumber = string.Empty; libssl.CertificateData(@txtCerPath.Text, out Certificate, out CertificateNumber); try { //get XML document and sign it XmlDocument xmldoc = new XmlDocument(); xmldoc.PreserveWhitespace = true; xmldoc.Load(txtXMLFile.Text); string signedString = libssl.SignString(@txtKeyPath.Text, "..L3oyS4m..", xmldoc.InnerXml); txtResultMessages.Text = "Original String: " + xmldoc.InnerXml + " \nSigned string: " + signedString + " \nCertificate data: " + Certificate + " | Certificate number: " + CertificateNumber; } catch (XmlException xmle) { txtResultMessages.Text = "Problem while loading xml file: " + xmle.Message; } //txtResultMessages.Text= "Signed String:" + libssl.SignString(txtKeyPath.Text, "..S4myL3o..", cadenaOriginal); return; } }
//using code public void Test() { opensslkeycsharp libssl = new opensslkeycsharp(); string SignedString = libssl.SignString(@"c:\fiel\aaaa121213123123aaa_t.key", "0123456789", "||3.2|test|cadena|original|"); string Certificate = ""; string CertificateNumber = ""; libssl.CertificateData(@"c:\fiel\aaaa121213123123aaa_t.cer", out Certificate, out CertificateNumber); }